Tracking at/in/every jobs.
In order of trigger time.
Methods
public class
public instance
protected instance
Constants
| JOB_TYPES | = | { :at => Rufus::Scheduler::AtJob, :in => Rufus::Scheduler::InJob, :every => Rufus::Scheduler::EveryJob } | Mapping :at|:in|:every to their respective job classes. |
Public class methods
new
()
[show 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)
Adds this job to the map.
[show source]
# File lib/rufus/sc/jobqueues.rb, line 68 68: def << (job) 69: 70: @mutex.synchronize do 71: delete(job.job_id) 72: @jobs << job 73: @jobs.sort! { |j0, j1| j0.at <=> j1.at } 74: end 75: end
job_to_trigger
()
Returns the next job to trigger. Returns nil if none eligible.
[show source]
# File lib/rufus/sc/jobqueues.rb, line 55 55: def job_to_trigger 56: 57: @mutex.synchronize do 58: if @jobs.size > 0 && Time.now.to_f >= @jobs.first.at 59: @jobs.shift 60: else 61: nil 62: end 63: end 64: end
select
(type)
Returns a list of jobs of the given type (:at|:in|:every)
[show source]
# File lib/rufus/sc/jobqueues.rb, line 93 93: def select (type) 94: 95: type = JOB_TYPES[type] 96: @jobs.select { |j| j.is_a?(type) } 97: end
size
()
[show source]
# File lib/rufus/sc/jobqueues.rb, line 99 99: def size 100: 101: @jobs.size 102: end
to_h
()
Returns a mapping job_id => job
[show source]
# File lib/rufus/sc/jobqueues.rb, line 86 86: def to_h 87: 88: @jobs.inject({}) { |h, j| h[j.job_id] = j; h } 89: end
unschedule
(job_id)
Removes a job (given its id). Returns nil if the job was not found.
[show source]
# File lib/rufus/sc/jobqueues.rb, line 79 79: def unschedule (job_id) 80: 81: @mutex.synchronize { delete(job_id) } 82: end
Protected instance methods
delete
(job_id)
[show source]
# File lib/rufus/sc/jobqueues.rb, line 106 106: def delete (job_id) 107: j = @jobs.find { |j| j.job_id == job_id } 108: @jobs.delete(j) if j 109: j 110: end