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.



400
401
402
403
404
# File 'lib/wurk/cron.rb', line 400

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

Instance Attribute Details

#loopsObject (readonly)

Returns the value of attribute loops.



398
399
400
# File 'lib/wurk/cron.rb', line 398

def loops
  @loops
end

#tzObject

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



406
407
408
409
410
411
412
413
414
# File 'lib/wurk/cron.rb', line 406

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