Class: Docket::Repeater
- Inherits:
-
Object
- Object
- Docket::Repeater
- Defined in:
- lib/docket/repeater.rb
Instance Attribute Summary collapse
-
#frequencies ⇒ Object
Returns the value of attribute frequencies.
-
#perform_action ⇒ Object
Returns the value of attribute perform_action.
-
#perform_on ⇒ Object
Returns the value of attribute perform_on.
-
#repeat ⇒ Object
readonly
Returns the value of attribute repeat.
-
#scheduler ⇒ Object
Returns the value of attribute scheduler.
-
#scheduler_action ⇒ Object
Returns the value of attribute scheduler_action.
-
#scheduler_set_callback ⇒ Object
Returns the value of attribute scheduler_set_callback.
-
#storage ⇒ Object
readonly
Returns the value of attribute storage.
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ Repeater
constructor
A new instance of Repeater.
- #items_for(frequency) ⇒ Object
- #repeated_items ⇒ Object
- #set ⇒ Object
- #stop(force = false) ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Repeater
Returns a new instance of Repeater.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/docket/repeater.rb', line 10 def initialize args={} @frequencies = args[:frequencies] @perform_action = args[:perform_action] @perform_on = args[:perform_on] @scheduler = args[:scheduler] || Rufus::Scheduler.new @scheduler_action = args[:scheduler_action] @scheduler_set_callback = args[:scheduler_set_callback] || lambda {|scheduler|} @storage = args[:storage] || Docket.configuration.storage || Docket::Storage::Daybreak.new('/tmp/docket.rb') @repeat = args[:repeat] end |
Instance Attribute Details
#frequencies ⇒ Object
Returns the value of attribute frequencies.
6 7 8 |
# File 'lib/docket/repeater.rb', line 6 def frequencies @frequencies end |
#perform_action ⇒ Object
Returns the value of attribute perform_action.
6 7 8 |
# File 'lib/docket/repeater.rb', line 6 def perform_action @perform_action end |
#perform_on ⇒ Object
Returns the value of attribute perform_on.
6 7 8 |
# File 'lib/docket/repeater.rb', line 6 def perform_on @perform_on end |
#repeat ⇒ Object (readonly)
Returns the value of attribute repeat.
8 9 10 |
# File 'lib/docket/repeater.rb', line 8 def repeat @repeat end |
#scheduler ⇒ Object
Returns the value of attribute scheduler.
6 7 8 |
# File 'lib/docket/repeater.rb', line 6 def scheduler @scheduler end |
#scheduler_action ⇒ Object
Returns the value of attribute scheduler_action.
6 7 8 |
# File 'lib/docket/repeater.rb', line 6 def scheduler_action @scheduler_action end |
#scheduler_set_callback ⇒ Object
Returns the value of attribute scheduler_set_callback.
6 7 8 |
# File 'lib/docket/repeater.rb', line 6 def scheduler_set_callback @scheduler_set_callback end |
#storage ⇒ Object (readonly)
Returns the value of attribute storage.
8 9 10 |
# File 'lib/docket/repeater.rb', line 8 def storage @storage end |
Instance Method Details
#items_for(frequency) ⇒ Object
25 26 27 |
# File 'lib/docket/repeater.rb', line 25 def items_for frequency Array(storage.read(frequency)) end |
#repeated_items ⇒ Object
21 22 23 |
# File 'lib/docket/repeater.rb', line 21 def repeated_items frequencies.collect { |frequency| items_for frequency }.compact.flatten end |
#set ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/docket/repeater.rb', line 29 def set frequencies.each do |frequency| if scheduler_action scheduler_action.call(self, frequency) else scheduler.every(frequency, :times => repeat) do items_for(frequency).each { |key| perform_on.perform(key, perform_action) } end end end scheduler_set_callback.call(scheduler) end |
#stop(force = false) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/docket/repeater.rb', line 44 def stop force=false if force scheduler.shutdown(:kill) else scheduler.shutdown(:wait) end end |