Schedule a background job with Sidekiq

I have a Rails 3 application deployed to a hero. I have a Sidekiq worker in app/workers/task_worker.rb :

 class TaskWorker include Sidekiq::Worker def perform ... end end 

How to schedule TaskWorker.perform_async daily at 12:01 am.m?

+4
source share
3 answers

You might also want to take a look at sidetiq . https://github.com/tobiassvn/sidetiq Gem supports complex expressions of the time with the ice_cube .

I personally found it convenient to have a gem that seamlessly integrates with sidekiq.

Something like this should work:

 class TaskWorker include Sidekiq::Worker include Sidetiq::Schedulable recurrence do daily.hour_of_day(0).minute_of_hour(1) end def perform # do magic end end 

Caution, however, when using this gem, as there are some performance problems with some expressions of time. https://github.com/tobiassvn/sidetiq/wiki/Known-Issues . The expression I gave you should get around this problem though.

+5
source

I don’t like the overhead. Sidetiq adds Sidekiq, so I was looking for another solution.

Heroku apparently has a little-known but free add-on for the scheduler , which allows you to run rake tasks every 10 minutes, hourly or daily. This is Heroku's answer to cron jobs, and it's nice that it's a free add-on. It should work for most non-critical schedules.

Heroku states in its documents that the scheduler is a β€œBest effort” service that can sometimes (but rarely) skip a scheduled event. If it is important that this task is completed, you probably want to use a custom clock process . Custom clock processes are more reliable, but they are counted according to your dynamic clock. (And as such, bear fees like any other process.)

Currently, it looks like clockwork - the recommended clock process on Heroku.

+2
source

I state the obvious, but what happened to the Cron Job starting Sidekiq every night at that time?

-3
source

Source: https://habr.com/ru/post/1489732/


All Articles