Class: Ellen::Cron::Job
- Inherits:
-
Object
- Object
- Ellen::Cron::Job
- Defined in:
- lib/ellen/cron/job.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#thread ⇒ Object
readonly
Returns the value of attribute thread.
Instance Method Summary collapse
- #body ⇒ Object
- #description ⇒ Object
- #from ⇒ Object
- #id ⇒ Object
-
#initialize(attributes) ⇒ Job
constructor
A new instance of Job.
- #schedule ⇒ Object
- #start(robot) ⇒ Object
- #stop ⇒ Object
- #to ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(attributes) ⇒ Job
Returns a new instance of Job.
6 7 8 |
# File 'lib/ellen/cron/job.rb', line 6 def initialize(attributes) @attributes = attributes.stringify_keys end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
4 5 6 |
# File 'lib/ellen/cron/job.rb', line 4 def attributes @attributes end |
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
4 5 6 |
# File 'lib/ellen/cron/job.rb', line 4 def thread @thread end |
Instance Method Details
#body ⇒ Object
40 41 42 |
# File 'lib/ellen/cron/job.rb', line 40 def body attributes["body"] end |
#description ⇒ Object
28 29 30 |
# File 'lib/ellen/cron/job.rb', line 28 def description %<%5s: "%s" %s> % [id, schedule, body] end |
#from ⇒ Object
44 45 46 |
# File 'lib/ellen/cron/job.rb', line 44 def from attributes["from"] end |
#id ⇒ Object
32 33 34 |
# File 'lib/ellen/cron/job.rb', line 32 def id attributes["id"] end |
#schedule ⇒ Object
36 37 38 |
# File 'lib/ellen/cron/job.rb', line 36 def schedule attributes["schedule"] end |
#start(robot) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/ellen/cron/job.rb', line 10 def start(robot) @thread = Thread.new do Chrono::Trigger.new(schedule) do Message.new( attributes.symbolize_keys.except(:body, :id, :schedule).merge(robot: robot) ).reply(body) end.run end end |
#stop ⇒ Object
24 25 26 |
# File 'lib/ellen/cron/job.rb', line 24 def stop thread.kill end |
#to ⇒ Object
48 49 50 |
# File 'lib/ellen/cron/job.rb', line 48 def to attributes["to"] end |
#to_hash ⇒ Object
20 21 22 |
# File 'lib/ellen/cron/job.rb', line 20 def to_hash attributes end |