Class: Wurk::Cron::Manager
- Inherits:
-
Object
- Object
- Wurk::Cron::Manager
- Defined in:
- lib/wurk/cron.rb
Overview
Registration DSL. One Manager per config.periodic block; multiple
blocks accumulate. mgr.tz= sets the default tz for subsequent
register calls; per-call tz: overrides.
Instance Attribute Summary collapse
-
#loops ⇒ Object
readonly
Returns the value of attribute loops.
-
#tz ⇒ Object
Returns the value of attribute tz.
Instance Method Summary collapse
-
#initialize(config = nil, prune: true) ⇒ Manager
constructor
prune: falseregisters without superseding — ConfigTester uses it so validating a config never deletes a live loop. - #register(cron, klass, **opts) ⇒ Object
Constructor Details
#initialize(config = nil, prune: true) ⇒ Manager
prune: false registers without superseding — ConfigTester uses it so
validating a config never deletes a live loop.
402 403 404 405 406 407 408 |
# File 'lib/wurk/cron.rb', line 402 def initialize(config = nil, prune: true) @config = config @loops = [] @tz = nil @prune = prune @pruned_klasses = {} end |
Instance Attribute Details
#loops ⇒ Object (readonly)
Returns the value of attribute loops.
398 399 400 |
# File 'lib/wurk/cron.rb', line 398 def loops @loops end |
#tz ⇒ Object
Returns the value of attribute tz.
397 398 399 |
# File 'lib/wurk/cron.rb', line 397 def tz @tz end |
Instance Method Details
#register(cron, klass, **opts) ⇒ Object
410 411 412 413 414 415 416 417 418 419 |
# File 'lib/wurk/cron.rb', line 410 def register(cron, klass, **opts) klass_name = klass.is_a?(String) ? klass : klass.to_s tz = opts.delete(:tz) || @tz normalized = opts.transform_keys(&:to_s) loop_obj = Loop.new(schedule: cron, klass: klass_name, options: normalized, tz: tz) @loops << loop_obj Cron.persist(loop_obj) prune_superseded(klass_name) loop_obj end |