mattyr / sidecloq

Recurring / Periodic / Scheduled / Cron job extension for Sidekiq
MIT License
88 stars 12 forks source link

Incorrect handling of environment specification, undefined method "split" for nil:NilClass #42

Closed vanboom closed 2 years ago

vanboom commented 2 years ago

We are trying to configure a production only job per the README example:

production:
  checkout_scanner:
    class: Jobs::Scanner
    cron: "5,15,30,45 * * * *"

But are getting an exception...

#<Thread:0x00005619bb5df518@/data/gems/sidecloq/lib/sidecloq/runner.rb:15 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
    8: from /data/gems/sidecloq/lib/sidecloq/runner.rb:17:in `block in run'
    7: from /data/gems/sidecloq/lib/sidecloq/locker.rb:29:in `with_lock'
    6: from /data/gems/sidecloq/lib/sidecloq/runner.rb:20:in `block (2 levels) in run'
    5: from /data/gems/sidecloq/lib/sidecloq/scheduler.rb:19:in `run'
    4: from /data/gems/sidecloq/lib/sidecloq/scheduler.rb:49:in `load_schedule_into_rufus'
    3: from /data/gems/sidecloq/lib/sidecloq/scheduler.rb:49:in `each'
    2: from /data/gems/sidecloq/lib/sidecloq/scheduler.rb:50:in `block in load_schedule_into_rufus'
    1: from /data/gems/sidecloq/lib/sidecloq/scheduler.rb:59:in `load_into_rufus'
/data/gems/sidecloq/lib/sidecloq/utils.rb:49:in `will_never_run': undefined method `split' for nil:NilClass (NoMethodError)

Putting some debug in to print @schedule.job_specs it appears that the environment option is not being handled in the YML I might be missing something obvious, appreciate any tips or suggestions.

{
    "production" => {
        "checkout_scanner" => {
            "class" => "Jobs::Scanner",
             "cron" => "5,15,30,45 * * * *"
        },
                   "class" => "production",
                    "args" => []
    }
}
vanboom commented 2 years ago

UPDATE: it appears that when using the environment option, all environments must be present in the YML, e.g.

development: {}
production:
  checkout_scanner:
    class: Jobs::Scanner
    cron: "5,15,30,45 * * * *"
test: {}

With empty environments declared, everything works great. Thanks for a great gem!