Class: Ruboty::Cron::Job
- Inherits:
-
Object
- Object
- Ruboty::Cron::Job
- Defined in:
- lib/ruboty/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
- #id ⇒ Object
-
#initialize(attributes) ⇒ Job
constructor
A new instance of Job.
- #schedule ⇒ Object
- #start(robot) ⇒ Object
- #stop ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(attributes) ⇒ Job
Returns a new instance of Job.
6 7 8 |
# File 'lib/ruboty/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/ruboty/cron/job.rb', line 4 def attributes @attributes end |
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
4 5 6 |
# File 'lib/ruboty/cron/job.rb', line 4 def thread @thread end |
Instance Method Details
#body ⇒ Object
43 44 45 |
# File 'lib/ruboty/cron/job.rb', line 43 def body attributes["body"] end |
#description ⇒ Object
31 32 33 |
# File 'lib/ruboty/cron/job.rb', line 31 def description %<%5s: "%s" %s> % [id, schedule, body] end |
#id ⇒ Object
35 36 37 |
# File 'lib/ruboty/cron/job.rb', line 35 def id attributes["id"] end |
#schedule ⇒ Object
39 40 41 |
# File 'lib/ruboty/cron/job.rb', line 39 def schedule attributes["schedule"] end |
#start(robot) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/ruboty/cron/job.rb', line 10 def start(robot) @thread = Thread.new do Chrono::Trigger.new(schedule) do robot.receive( attributes.symbolize_keys.except( :id, :schedule, ), ) end.run end end |
#stop ⇒ Object
27 28 29 |
# File 'lib/ruboty/cron/job.rb', line 27 def stop thread.kill end |
#to_hash ⇒ Object
23 24 25 |
# File 'lib/ruboty/cron/job.rb', line 23 def to_hash attributes end |