class Rufus::Scheduler::JobArray

The array rufus-scheduler uses to keep jobs in order (next to trigger first).

Public Class Methods

new() click to toggle source
# File lib/rufus/scheduler/job_array.rb, line 8
def initialize

  @mutex = Mutex.new
  @array = []
end

Public Instance Methods

[](job_id) click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/rufus/scheduler/job_array.rb, line 14
def push(job)

  @mutex.synchronize { @array << job unless @array.index(job) }

  self
end
size() click to toggle source
# File lib/rufus/scheduler/job_array.rb, line 21
def size

  @array.size
end
to_a() click to toggle source
# File lib/rufus/scheduler/job_array.rb, line 47
def to_a

  @mutex.synchronize { @array.dup }
end
unschedule_all() click to toggle source
# File lib/rufus/scheduler/job_array.rb, line 57
def unschedule_all

  @array.each(&:unschedule)
end