简体   繁体   中英

Process enqueued job with cron job - Sidekiq

I have a Ruby on Rails application that receives webhooks from Twilio, I don't want to process these webhooks immediately. What I want is:

  • Enqueue webhooks in the Redis queue
  • Schedule a cron-job to get jobs from the queue after a specific interval and process them based on some condition
  • This will process jobs after specific intervals and I will be able to control the frequency of corn jobs to process jobs.

The application already has a working setup of Sidekiq with Redis, but I'm unable to find a way to enqueue jobs and perform later with the help of corn job.

Any suggestions on how I can achieve the above functionality? I really appreciate any help you can provide.

You can try this approach:

  • Create a new model for example TwilioResponse that holding the data posting to your webhook, probably with a flag to indicate if it has been processed.
  • Whenever data coming, create a new instance of that model and save into the database
  • Schedule cronjob for a task to grab all unprocessed TwilioResponse instances and process them, this maybe moved to Sidekiq or just process directly in the task
  • After process a TwilioResponse model, set the flag to processed

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