Class: Rufus::Scheduler::JobArray
- Inherits:
-
Object
- Object
- Rufus::Scheduler::JobArray
- Defined in:
- lib/rufus/scheduler/job_array.rb
Overview
The array rufus-scheduler uses to keep jobs in order (next to trigger first).
Instance Method Summary collapse
- #[](job_id) ⇒ Object
- #delete_unscheduled ⇒ Object
- #each(now, &block) ⇒ Object
-
#initialize ⇒ JobArray
constructor
A new instance of JobArray.
- #push(job) ⇒ Object
- #size ⇒ Object
- #to_a ⇒ Object
- #unschedule_all ⇒ Object
Constructor Details
#initialize ⇒ JobArray
Returns a new instance of JobArray.
8 9 10 11 12 |
# File 'lib/rufus/scheduler/job_array.rb', line 8 def initialize @mutex = Mutex.new @array = [] end |
Instance Method Details
#[](job_id) ⇒ Object
52 53 54 55 |
# File 'lib/rufus/scheduler/job_array.rb', line 52 def [](job_id) @mutex.synchronize { @array.find { |j| j.job_id == job_id } } end |
#delete_unscheduled ⇒ Object
41 42 43 44 45 |
# File 'lib/rufus/scheduler/job_array.rb', line 41 def delete_unscheduled @mutex.synchronize { @array.delete_if { |j| j.next_time.nil? || j.unscheduled_at } } end |
#each(now, &block) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rufus/scheduler/job_array.rb', line 26 def each(now, &block) to_a.sort_by do |job| job.next_time || (now + 1) end.each do |job| nt = job.next_time break if ( ! nt) || (nt > now) block.call(job) end end |
#push(job) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/rufus/scheduler/job_array.rb', line 14 def push(job) @mutex.synchronize { @array << job unless @array.index(job) } self end |
#size ⇒ Object
21 22 23 24 |
# File 'lib/rufus/scheduler/job_array.rb', line 21 def size @array.size end |
#to_a ⇒ Object
47 48 49 50 |
# File 'lib/rufus/scheduler/job_array.rb', line 47 def to_a @mutex.synchronize { @array.dup } end |
#unschedule_all ⇒ Object
57 58 59 60 |
# File 'lib/rufus/scheduler/job_array.rb', line 57 def unschedule_all @array.each(&:unschedule) end |