Search code examples
ruby-on-railsdockersidekiqrails-activejob

Sidekiq jobs aren't firing in development mode, only in production


Edit: I was just told by our team that docker is not even used for production. So it seems the issue is limited to Docker and not the environments that Rails is launching into.

I have a project I'm working on sidekiq jobs seem to run fine in our production environment, but in my local development machine I get a bunch of console errors for sidekiq and I'm not sure why.

Here are my sidekiq errors:

sidekiq_1  | 2017-03-15T17:16:24.346Z 1 TID-gq075lic0 INFO: Booting Sidekiq 4.2.3 with redis options {:url=>"redis://redis:6379/"}
sidekiq_1  | 2017-03-15T17:16:25.240Z 1 TID-gq075lic0 INFO: Running in ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
sidekiq_1  | 2017-03-15T17:16:25.240Z 1 TID-gq075lic0 INFO: See LICENSE and the LGPL-3.0 for licensing details.
sidekiq_1  | 2017-03-15T17:16:25.241Z 1 TID-gq075lic0 INFO: Upgrade to Sidekiq Pro for more features and support: http://sidekiq.org
sidekiq_1  | 2017-03-15T17:16:25.260Z 1 TID-gq075lic0 INFO: Loading Schedule
sidekiq_1  | 2017-03-15T17:16:25.260Z 1 TID-gq075lic0 INFO: Schedule empty! Set Sidekiq.schedule
sidekiq_1  | 2017-03-15T17:16:25.264Z 1 TID-gq075lic0 INFO: Schedules Loaded
sidekiq_1  | 2017-03-15T17:16:25.266Z 1 TID-gq075lic0 WARN: {"context":"Exception during Sidekiq lifecycle event.","event":"startup"}
sidekiq_1  | 2017-03-15T17:16:25.266Z 1 TID-gq075lic0 WARN: TypeError: can't dup NilClass
sidekiq_1  | 2017-03-15T17:16:25.267Z 1 TID-gq075lic0 WARN: /usr/local/bundle/gems/sidekiq-scheduler-2.0.19/lib/sidekiq-scheduler/schedule.rb:126:in `dup'
sidekiq_1  | /usr/local/bundle/gems/sidekiq-scheduler-2.0.19/lib/sidekiq-scheduler/schedule.rb:126:in `block in prepare_schedule'
sidekiq_1  | /usr/local/bundle/gems/sidekiq-scheduler-2.0.19/lib/sidekiq-scheduler/schedule.rb:125:in `each'
sidekiq_1  | /usr/local/bundle/gems/sidekiq-scheduler-2.0.19/lib/sidekiq-scheduler/schedule.rb:125:in `prepare_schedule'
sidekiq_1  | /usr/local/bundle/gems/sidekiq-scheduler-2.0.19/lib/sidekiq-scheduler/schedule.rb:40:in `schedule='
sidekiq_1  | /gathrly/config/initializers/scheduler.rb:5:in `block (2 levels) in <top (required)>'
sidekiq_1  | /usr/local/bundle/gems/sidekiq-4.2.3/lib/sidekiq/util.rb:54:in `block in fire_event'
sidekiq_1  | /usr/local/bundle/gems/sidekiq-4.2.3/lib/sidekiq/util.rb:52:in `each'
sidekiq_1  | /usr/local/bundle/gems/sidekiq-4.2.3/lib/sidekiq/util.rb:52:in `fire_event'
sidekiq_1  | /usr/local/bundle/gems/sidekiq-4.2.3/lib/sidekiq/cli.rb:79:in `run'
sidekiq_1  | /usr/local/bundle/gems/sidekiq-4.2.3/bin/sidekiq:12:in `<top (required)>'
sidekiq_1  | /usr/local/bundle/bin/sidekiq:17:in `load'
sidekiq_1  | /usr/local/bundle/bin/sidekiq:17:in `<top (required)>'
sidekiq_1  | /usr/local/bundle/gems/bundler-1.14.6/lib/bundler/cli/exec.rb:74:in `load'
sidekiq_1  | /usr/local/bundle/gems/bundler-1.14.6/lib/bundler/cli/exec.rb:74:in `kernel_load'
sidekiq_1  | /usr/local/bundle/gems/bundler-1.14.6/lib/bundler/cli/exec.rb:27:in `run'
sidekiq_1  | /usr/local/bundle/gems/bundler-1.14.6/lib/bundler/cli.rb:335:in `exec'
sidekiq_1  | /usr/local/bundle/gems/bundler-1.14.6/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
sidekiq_1  | /usr/local/bundle/gems/bundler-1.14.6/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
sidekiq_1  | /usr/local/bundle/gems/bundler-1.14.6/lib/bundler/vendor/thor/lib/thor.rb:359:in `dispatch'
sidekiq_1  | /usr/local/bundle/gems/bundler-1.14.6/lib/bundler/cli.rb:20:in `dispatch'
sidekiq_1  | /usr/local/bundle/gems/bundler-1.14.6/lib/bundler/vendor/thor/lib/thor/base.rb:440:in `start'
sidekiq_1  | /usr/local/bundle/gems/bundler-1.14.6/lib/bundler/cli.rb:11:in `start'
sidekiq_1  | /usr/local/bundle/gems/bundler-1.14.6/exe/bundle:32:in `block in <top (required)>'
sidekiq_1  | /usr/local/bundle/gems/bundler-1.14.6/lib/bundler/friendly_errors.rb:121:in `with_friendly_errors'
sidekiq_1  | /usr/local/bundle/gems/bundler-1.14.6/exe/bundle:24:in `<top (required)>'
sidekiq_1  | /usr/local/bundle/bin/bundle:22:in `load'
sidekiq_1  | /usr/local/bundle/bin/bundle:22:in `<main>'
sidekiq_1  | 2017-03-15T17:16:25.268Z 1 TID-gq075lic0 INFO: Starting processing, hit Ctrl-C to stop
web_1      | Puma starting in single mode...
web_1      | * Version 3.6.0 (ruby 2.3.1-p112), codename: Sleepy Sunday Serenity
web_1      | * Min threads: 5, max threads: 5
web_1      | * Environment: development
web_1      | * Listening on tcp://0.0.0.0:3000

It says:

sidekiq_1  | 2017-03-15T17:16:25.260Z 1 TID-gq075lic0 INFO: Loading Schedule
sidekiq_1  | 2017-03-15T17:16:25.260Z 1 TID-gq075lic0 INFO: Schedule empty! Set Sidekiq.schedule
sidekiq_1  | 2017-03-15T17:16:25.264Z 1 TID-gq075lic0 INFO: Schedules Loaded

But then I get a NilClass error.

Here is my scheduler.rb file:

require 'sidekiq/scheduler'

Sidekiq.configure_server do |config|
  config.on(:startup) do
    Sidekiq.schedule = YAML.load_file(File.expand_path('../../sidekiq_scheduler.yml', __FILE__))
    Sidekiq::Scheduler.reload_schedule!
  end
end

and my sidekiq-scheduler.rb file:

UpdateEventbriteJob:
  cron: "*/15 * * * *"
UpdateMeetupJob:
  cron: "*/15 * * * *"
PostEventEmailJob:
  # cron: "0 9 * * *"
  # cron: "*/1 * * * *"
UpdateStatusJob:
  cron: "*/1 * * * *" # Every minute for testing. Plan on every 24 hours

I'm testing the UpdateStatusJob locally. The other jobs working production and seem to work fine. But Nothing in this scheduler ever fires in develop mode. I would like to test the job out before I kick it up to production. What am I doing wrong?

I should also note I'm running things in docker. Something I don't use too often so I'm not sure if that's impeding things.

Here is the relevant information in my docker-compose file:

version: '2'
services:

  ...

  sidekiq:
    build: .
    command: bundle exec sidekiq -C config/sidekiq.yml
    env_file: .env
    links:
      - db
      - redis

  ...

Solution

  • In the scheduler.yml PostEventEmailJob doesn't have any values, only commented out lines.

    If you change the file to:

    UpdateEventbriteJob:
      cron: "*/15 * * * *"
    UpdateMeetupJob:
      cron: "*/15 * * * *"
    PostEventEmailJob:
      cron: "0 9 * * *"
    UpdateStatusJob:
      cron: "*/1 * * * *" # Every minute for testing. Plan on every 24 hours
    

    it will parse correctly and start Sidekiq.