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



416
417
418
419
420
421
422
423
424
425
426
427
428
429
# File 'lib/wurk/cron.rb', line 416

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

  mgr = Manager.new
  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