I have sidkiq configured as following.
# config/initializers/sidekiq.rb
require 'sidekiq/web'
Sidekiq::Web.use(Rack::Protection, origin_whitelist: ['https://mysite'])
redis_config = { url: ENV['SIDEKIQ_REDIS_URL'] }
Sidekiq.configure_server do |config|
config.redis = redis_config
config.average_scheduled_poll_interval = 1
config.periodic do |mgr|
mgr.register('* 2 * * *', 'MyPeriodicWorker') # 2am daily
end
end
Sidekiq.configure_client do |config|
config.redis = redis_config
end
After I built docker image locally, I ran it from my laptop and it did work.
[Patch] Preventing bunny channel leak
2020-11-26T09:01:45.452Z pid=1 tid=gq3ufhkop INFO: Booting Sidekiq 6.0.7 with redis options
{:url=>"redis://127.0.0.1:56379/4"}
2020-11-26T09:01:46.705Z pid=1 tid=gq3ufhkop INFO: Booted Rails 6.0.3.1 application in
staging environment
2020-11-26T09:01:46.705Z pid=1 tid=gq3ufhkop INFO: Running in ruby 2.6.5p114 (2019-10-01
revision 67812) [x86_64-linux-musl]
2020-11-26T09:01:46.705Z pid=1 tid=gq3ufhkop INFO: Sidekiq Pro 5.0.1 / Sidekiq Enterprise
2.0.1, commercially licensed.
2020-11-26T09:01:46.721Z pid=1 tid=gq3v7vxkt INFO: Managing 1 periodic jobs
2020-11-26T09:01:46.724Z pid=1 tid=gq3v7vxkt INFO: Gained leadership of the cluster
But when I deployed it to k8s cluster, it didn’t.
[Patch] Preventing bunny channel leak
2020-11-26T08:17:01.324Z pid=1 tid=gtmxb31mt INFO: Booting Sidekiq 6.0.7 with redis options
{:url=>"redis://:REDACTED@myredisinstance:6379/4"}
2020-11-26T08:17:02.406Z pid=1 tid=gtmxb31mt INFO: Booted Rails 6.0.3.1 application in
staging environment
2020-11-26T08:17:02.406Z pid=1 tid=gtmxb31mt INFO: Running in ruby 2.6.5p114 (2019-10-01
revision 67812) [x86_64-linux-musl]
2020-11-26T08:17:02.406Z pid=1 tid=gtmxb31mt INFO: Sidekiq Pro 5.0.1 / Sidekiq Enterprise
2.0.1, commercially licensed.
What makes the difference?
2
Answers
On k8
mgr.register('* 2 * * *', 'MyPeriodicWorker')
command is not executing. Try to echo at that time. Maybe you are not having permission to update crontab. and may be you need to usesudo
somehow.In a cluster, only one Sidekiq process manages/enqueues the periodic jobs (otherwise duplicate Sidekiq processes would create duplicate periodic jobs!). Your example process did not get cluster leadership and so is not in control of the periodic jobs.