0

I'm not sure what I'm missing with my Sidekiq Scheduler setup. I can process jobs manually, but the scheduled jobs aren't running. Pressing Enqueue Now from the Web ui runs the job correctly. Starting sidekiq with bundle exec sidekiq says Schedules Loaded

Gemfile

gem 'sidekiq', '~> 6.5.4'
gem 'sidekiq-scheduler', '~> 5.0.3'

config/initializers/sidekiq.rb

if Rails.env.test?
  require 'sidekiq/testing'

  Sidekiq::Testing.fake!
else
  Sidekiq.configure_server do |config|
    config.average_scheduled_poll_interval = 5
    config.on(:startup) do
      SidekiqScheduleManager::StartupManager.call
      Sidekiq.schedule = Sidekiq.get_all_schedules
    end
  end
  Sidekiq.configure_client do |config|
    config.average_scheduled_poll_interval = 5
  end
end

Creating a schedule with

def schedule_this(day)
  # Convert seconds since midnight to a time string,
  # The current time doesn't matter, we just need the time at the beginning of the day
  time = (Time.current.beginning_of_day + daily_schedule[day].seconds).strftime('%H:%M')
  # Schedule the job
  Sidekiq.set_schedule(
    "notify_#{member.id}_#{day}",
    schedule_arg(day, time, member)
  )
end

def schedule_arg(day, time, member)
  {
    # 'every' => ['1w', { 'first_at' => "#{day.capitalize} #{time}" }],
    # 'every' => "#{day} at #{time}",
    # 'every' => ['1w', { 'first_in' => "#{day} at #{time}" }],
    'cron' => Fugit::Nat.parse("every #{day} at #{time}").original,
    'class' => 'WaveJob',
    'args' => schedule_args_args(member)
  }
end

set_schedule produces records like this

{"notify_649754255af1d03b3aecba50_monday"=>{"cron"=>"0 9 * * 1", "class"=>"WaveJob", "args"=>"[some_json]"},

Update - Adding Sidekiq::Scheduler.reload_schedule! to the :startup block gets the jobs to process now, but editing a record's cron string isn't updating the schedules again. Re-running reload_schedule! from the console says SidekiqScheduler is disabled.

Update - Fixed it. Just needed Sidekiq::Scheduler.dynamic = true in the :startup block as well

teddybear
  • 546
  • 2
  • 6
  • 14

0 Answers0