Periodic Tasks with sidekiq-cron

#61 Periodic Tasks with sidekiq-cron
1/2/2017

Summary

Using a third-party add-on, sidekiq-cron, we can create periodic tasks to extend the functionality of sidekiq.
1
rails background processing 4:59 min

Summary

Gemfilegem 'sidekiq-cron'
config/initializers/sidekiq.rbSidekiq.configure_server do |config|
  config.redis = { url: 'redis://localhost:6379/0'  }
  schedule_file = "config/schedule.yml"
  if File.exists?(schedule_file)
    Sidekiq::Cron::Job.load_from_hash YAML.load_file(schedule_file)
  end
end

Sidekiq.configure_client do |config|
  config.redis = { url: 'redis://localhost:6379/0'  }
end
config/schedule.ymlgenerate_random_user:
  cron: "* * * * *"
  class: "GenerateRandomUserJob"
  queue: default
routes.rbRails.application.routes.draw do
  ...
  require 'sidekiq/web'
  require 'sidekiq/cron/web'
  mount Sidekiq::Web => '/sidekiq'
  ...
end






00000000000000000000000000000000?d=mm&f=y&s=64
frank004 said 6 months ago:

can we use  gem 'whenever' with the sidekiq-cron?

635114?v=3&s=64
kobaltz said 6 months ago:

You could. However, I would only do this if you need tasks ran on all of the web servers. The two should not conflict with each other.

544408?v=3&s=64
randomor said 6 months ago:

Thanks for the video. Are you sure this is for Sidekiq Pro/Enterprise only? Can't find the docs in the repo mentioning this restriction. 

635114?v=3&s=64
kobaltz said 6 months ago:

sidekiq-cron is a separate, third-party addon for sidekiq. It does not require Pro/Enterprise. My reference in the video was meant to say that without this gem (or another third-party), and to still have the periodic task functionality, you would have to use Pro/Enterprise.

142157?v=3&s=64
dancinglightning said 6 months ago:

Thanks, actually for that whole series on sidekiq. Maybe some testing coming up ?

Having deployed the cron, i had to restart the sidekiq service. Off course. 

As you have everything else nicely setup for copy/paste, adding the schedule.yml file would make it even easier for the next guy.

And i must admit that at first hearing i also understood that this was only for use with enterprise edition. Only a bit of checking and listening again cleared that up.

Thanks

Torsten

635114?v=3&s=64
kobaltz said 6 months ago:

I do plan on doing some testing. However, I think week after next, I'll be focusing on searchkick/elasticsearch.

I've updated the episode with the schedule.yml file. That was definitely an oversight, so thank you.

204978?v=3&s=64
naveedkakal said 6 months ago:

If I had sidekiq-pro, would this still be a good solution for scheduled jobs?  Or is there a built in sidekiq scheduler with pro?


I have been using the clockwork gem, but it requires me to maintain a 'special' mode, along with the gem author recently stopping maintenance on it.  Looking for alternatives and this definitely looks up my alley, thanks.

635114?v=3&s=64
kobaltz said 6 months ago:

I don't think that sidekiq-pro offers recurring jobs.

For terminology sake, a scheduled job would be the result of an action telling the background processor to schedule the job for a later time. For example, if a new user signs up for your application, you can set a scheduled job to thank the user for signing up and give some tips about your application 24 hours after they sign up.

A recurring job or periodic task, would be something where you are wanting to perform a task every x intervals. For example, if you have a ToDo list application and you want to send a notification to your users every morning with an overview of what they still need to do or have completed the previous day, sidekiq-cron would be a good fit for the job.

You should be able to use sidekiq-cron along side sidekiq-pro. However, if you're using sidekiq-enterprise, there is no need for sidekiq-cron since this functionality is built into sidekiq-enterprise.

45809?v=3&s=64
ondrejbartas said 5 months ago:

Thanks for very nice video about Sidekiq-Cron.

I  added link to readme to this vide if it is ok with you :D

635114?v=3&s=64
kobaltz said 5 months ago:

Thanks! Sounds good to me!

Login to Comment