Class: Elected::Scheduler::Job
- Inherits:
-
Object
- Object
- Elected::Scheduler::Job
- Includes:
- Logging
- Defined in:
- lib/elected/scheduler/job.rb
Instance Attribute Summary collapse
-
#callback ⇒ Object
readonly
Returns the value of attribute callback.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#schedules ⇒ Object
readonly
Returns the value of attribute schedules.
Instance Method Summary collapse
- #at(options = {}) ⇒ Object
- #execute ⇒ Object
-
#initialize(name, &blk) ⇒ Job
constructor
A new instance of Job.
- #matches?(time) ⇒ Boolean
- #run(&blk) ⇒ Object
- #to_s ⇒ Object (also: #inspect)
Constructor Details
#initialize(name, &blk) ⇒ Job
Returns a new instance of Job.
9 10 11 12 13 |
# File 'lib/elected/scheduler/job.rb', line 9 def initialize(name, &blk) @name = name.to_s @callback = blk if block_given? @schedules = Set.new end |
Instance Attribute Details
#callback ⇒ Object (readonly)
Returns the value of attribute callback.
7 8 9 |
# File 'lib/elected/scheduler/job.rb', line 7 def callback @callback end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/elected/scheduler/job.rb', line 7 def name @name end |
#schedules ⇒ Object (readonly)
Returns the value of attribute schedules.
7 8 9 |
# File 'lib/elected/scheduler/job.rb', line 7 def schedules @schedules end |
Instance Method Details
#at(options = {}) ⇒ Object
21 22 23 24 |
# File 'lib/elected/scheduler/job.rb', line 21 def at( = {}) schedules.add Schedule.new() self end |
#execute ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/elected/scheduler/job.rb', line 30 def execute callback.call true rescue Exception => e error "Exception: #{e.class.name} : #{e.}\n #{e.backtrace[0, 10].join("\n ")}" return false end |
#matches?(time) ⇒ Boolean
26 27 28 |
# File 'lib/elected/scheduler/job.rb', line 26 def matches?(time) schedules.any? { |s| s.matches? time } end |
#run(&blk) ⇒ Object
15 16 17 18 19 |
# File 'lib/elected/scheduler/job.rb', line 15 def run(&blk) raise 'must pass a block' unless block_given? @callback = blk self end |
#to_s ⇒ Object Also known as: inspect
38 39 40 |
# File 'lib/elected/scheduler/job.rb', line 38 def to_s %{#<#{self.class.name} name="#{name}" schedules=#{schedules.map { |x| x.to_s }.inspect}>} end |