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.
- #resume(robot) ⇒ Object
- #schedule ⇒ Object
- #start(robot) ⇒ Object
- #stop ⇒ Object
- #suspend ⇒ Object
- #suspended? ⇒ Boolean
- #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
53 54 55 |
# File 'lib/ruboty/cron/job.rb', line 53 def body attributes["body"] end |
#description ⇒ Object
41 42 43 |
# File 'lib/ruboty/cron/job.rb', line 41 def description %<%5s: (%s) "%s" %s> % [id, suspended? ? "suspended" : "active", schedule, body] end |
#id ⇒ Object
45 46 47 |
# File 'lib/ruboty/cron/job.rb', line 45 def id attributes["id"] end |
#resume(robot) ⇒ Object
36 37 38 39 |
# File 'lib/ruboty/cron/job.rb', line 36 def resume(robot) start(robot) attributes.delete("suspended") if attributes.has_key?("suspended") end |
#schedule ⇒ Object
49 50 51 |
# File 'lib/ruboty/cron/job.rb', line 49 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 |
#suspend ⇒ Object
31 32 33 34 |
# File 'lib/ruboty/cron/job.rb', line 31 def suspend stop attributes["suspended"] = true end |
#suspended? ⇒ Boolean
57 58 59 |
# File 'lib/ruboty/cron/job.rb', line 57 def suspended? !!attributes["suspended"] end |
#to_hash ⇒ Object
23 24 25 |
# File 'lib/ruboty/cron/job.rb', line 23 def to_hash attributes end |