Parent

Rufus::Scheduler::JobQueue

Tracking at/in/every jobs.

In order of trigger time.

Constants

JOB_TYPES

Mapping :at|:in|:every to their respective job classes.

Public Class Methods

new() click to toggle source
    # File lib/rufus/sc/jobqueues.rb, line 47
47:     def initialize
48: 
49:       @mutex = Mutex.new
50:       @jobs = []
51:     end

Public Instance Methods

<<(job) click to toggle source

Adds this job to the map.

    # File lib/rufus/sc/jobqueues.rb, line 66
66:     def <<(job)
67: 
68:       @mutex.synchronize do
69:         delete(job.job_id)
70:         @jobs << job
71:         @jobs.sort! { |j0, j1| j0.at <=> j1.at }
72:       end
73:     end
select(type) click to toggle source

Returns a list of jobs of the given type (:at|:in|:every)

    # File lib/rufus/sc/jobqueues.rb, line 91
91:     def select(type)
92: 
93:       type = JOB_TYPES[type]
94:       @jobs.select { |j| j.is_a?(type) }
95:     end
size() click to toggle source
     # File lib/rufus/sc/jobqueues.rb, line 97
 97:     def size
 98: 
 99:       @jobs.size
100:     end
to_h() click to toggle source

Returns a mapping job_id => job

    # File lib/rufus/sc/jobqueues.rb, line 84
84:     def to_h
85: 
86:       @jobs.inject({}) { |h, j| h[j.job_id] = j; h }
87:     end
trigger_matching_jobs() click to toggle source

Triggers all the jobs that are scheduled for ‘now’.

    # File lib/rufus/sc/jobqueues.rb, line 55
55:     def trigger_matching_jobs
56: 
57:       now = Time.now
58: 
59:       while job = job_to_trigger(now)
60:         job.trigger
61:       end
62:     end
unschedule(job_id) click to toggle source

Removes a job (given its id). Returns nil if the job was not found.

    # File lib/rufus/sc/jobqueues.rb, line 77
77:     def unschedule(job_id)
78: 
79:       @mutex.synchronize { delete(job_id) }
80:     end

Protected Instance Methods

delete(job_id) click to toggle source
     # File lib/rufus/sc/jobqueues.rb, line 104
104:     def delete(job_id)
105: 
106:       j = @jobs.find { |j| j.job_id == job_id }
107:       @jobs.delete(j) if j
108:     end
job_to_trigger(now) click to toggle source

Returns the next job to trigger. Returns nil if none eligible.

     # File lib/rufus/sc/jobqueues.rb, line 112
112:     def job_to_trigger(now)
113: 
114:       @mutex.synchronize do
115:         if @jobs.size > 0 && now.to_f >= @jobs.first.at
116:           @jobs.shift
117:         else
118:           nil
119:         end
120:       end
121:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.