简体   繁体   中英

Schedule Job each 10 seconds - ruby

I need a scheduler mechanism that will run each 10 seconds. I use sidekiq, and that's why i wanted to use sidekiq-cron, but the smallest time unit is one minute. Moreover, I need only one job instance running at a time.

What is the best practice for this situation?

By the way, we are using Rails 4.2, Ruby 2.1.2, Unicorn as web server and Sidekiq 3.

Thanks

EDIT: I need it to run every 10 seconds

Use a rake task that runs in a loop with a 10 second sleep. This rake task can create jobs that Sidekiq will execute immediately.

Sidekiq itself is not designed to solve this problem.

Sidekiq has scheduling methods: https://github.com/mperham/sidekiq/wiki/Scheduled-Jobs

So you can do

MyWorker.perform_in(10.seconds)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM