Class: Rufus::Scheduler::JobArray

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeJobArray



35
36
37
38
39
# File 'lib/rufus/scheduler/job_array.rb', line 35

def initialize

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

Instance Method Details

#[](job_id) ⇒ Object



77
78
79
80
# File 'lib/rufus/scheduler/job_array.rb', line 77

def [](job_id)

  @mutex.synchronize { @array.find { |j| j.job_id == job_id } }
end

#arrayObject

Only used when shutting down, directly yields the underlying array.



84
85
86
87
# File 'lib/rufus/scheduler/job_array.rb', line 84

def array

  @array
end

#delete_unscheduledObject



64
65
66
67
68
69
70
# File 'lib/rufus/scheduler/job_array.rb', line 64

def delete_unscheduled

  @mutex.synchronize {

    @array.delete_if { |j| j.next_time.nil? || j.unscheduled_at }
  }
end

#each(now, &block) ⇒ Object



53
54
55
56
57
58
59
60
61
62
# File 'lib/rufus/scheduler/job_array.rb', line 53

def each(now, &block)

  to_a.sort_by { |j| j.next_time || (now + 1) }.each do |job|

    break unless job.next_time
    break if job.next_time > now

    block.call(job)
  end
end

#push(job) ⇒ Object



41
42
43
44
45
46
# File 'lib/rufus/scheduler/job_array.rb', line 41

def push(job)

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

  self
end

#sizeObject



48
49
50
51
# File 'lib/rufus/scheduler/job_array.rb', line 48

def size

  @array.size
end

#to_aObject



72
73
74
75
# File 'lib/rufus/scheduler/job_array.rb', line 72

def to_a

  @mutex.synchronize { @array.dup }
end