Class: Wurk::Cron::Manager

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(config = nil) ⇒ Manager

Returns a new instance of Manager.



388
389
390
391
392
# File 'lib/wurk/cron.rb', line 388

def initialize(config = nil)
  @config = config
  @loops = []
  @tz = nil
end

Instance Attribute Details

#loopsObject (readonly)

Returns the value of attribute loops.



386
387
388
# File 'lib/wurk/cron.rb', line 386

def loops
  @loops
end

#tzObject

Returns the value of attribute tz.



385
386
387
# File 'lib/wurk/cron.rb', line 385

def tz
  @tz
end

Instance Method Details

#register(cron, klass, **opts) ⇒ Object



394
395
396
397
398
399
400
401
402
# File 'lib/wurk/cron.rb', line 394

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)
  loop_obj
end