Class: Wurk::Cron::ConfigTester

Inherits:
Object
  • Object
show all
Defined in:
lib/wurk/cron.rb

Overview

Boot-time validator. Runs the user's periodic block against a disposable Manager whose register call also resolves the klass constant — a typo'd class name surfaces here instead of on the first tick in production.

Instance Method Summary collapse

Instance Method Details

#verify(&block) ⇒ Object



490
491
492
493
494
495
496
497
498
499
500
501
502
503
# File 'lib/wurk/cron.rb', line 490

def verify(&block)
  raise ArgumentError, 'block required' unless block

  mgr = Manager.new(prune: false)
  block.call(mgr)
  mgr.loops.each { |lp| resolve_klass!(lp.klass) }
  mgr.loops
rescue StandardError
  # register persists each loop immediately, so a validation failure
  # would otherwise leave partially-applied loops in the live LoopSet —
  # they'd fire on the next poll. Roll the whole batch back, then re-raise.
  mgr&.loops&.each { |lp| Cron.unregister(lp.lid) }
  raise
end