Class: Scheddy::Config
- Inherits:
-
Object
- Object
- Scheddy::Config
- Defined in:
- lib/scheddy/config.rb
Instance Attribute Summary collapse
-
#tasks ⇒ Object
readonly
Returns the value of attribute tasks.
Instance Method Summary collapse
- #error_handler(block1 = nil, &block2) ⇒ Object
-
#initialize(tasks, &block) ⇒ Config
constructor
A new instance of Config.
-
#run_at(cron, name:, tag: :auto, track: :auto, &task) ⇒ Object
shortcut syntax.
-
#run_every(interval, name:, delay: nil, tag: :auto, track: :auto, &task) ⇒ Object
shortcut syntax.
- #task(name, &block) ⇒ Object
Constructor Details
#initialize(tasks, &block) ⇒ Config
Returns a new instance of Config.
15 16 17 18 |
# File 'lib/scheddy/config.rb', line 15 def initialize(tasks, &block) @tasks = tasks instance_eval(&block) end |
Instance Attribute Details
#tasks ⇒ Object (readonly)
Returns the value of attribute tasks.
11 12 13 |
# File 'lib/scheddy/config.rb', line 11 def tasks @tasks end |
Instance Method Details
#error_handler(block1 = nil, &block2) ⇒ Object
20 21 22 |
# File 'lib/scheddy/config.rb', line 20 def error_handler(block1=nil, &block2) Scheddy.error_handler = block1 || block2 end |
#run_at(cron, name:, tag: :auto, track: :auto, &task) ⇒ Object
shortcut syntax
30 31 32 33 34 35 36 37 |
# File 'lib/scheddy/config.rb', line 30 def run_at(cron, name:, tag: :auto, track: :auto, &task) task(name) do run_at cron logger_tag tag if tag != :auto track_runs track if track != :auto perform(&task) end end |
#run_every(interval, name:, delay: nil, tag: :auto, track: :auto, &task) ⇒ Object
shortcut syntax
40 41 42 43 44 45 46 47 48 |
# File 'lib/scheddy/config.rb', line 40 def run_every(interval, name:, delay: nil, tag: :auto, track: :auto, &task) task(name) do run_every interval initial_delay delay if delay logger_tag tag if tag != :auto track_runs track if track != :auto perform(&task) end end |
#task(name, &block) ⇒ Object
24 25 26 27 |
# File 'lib/scheddy/config.rb', line 24 def task(name, &block) raise ArgumentError, "Duplicate task name '#{name}'" if tasks.any?{|t| t.name == name} tasks.push TaskDefinition.new(name, &block).to_task end |