Sidekiq-Cron Gem Version Build Status Coverage Status

Add-on for Sidekiq

Allows you to schedule recurring jobs for sidekiq workers using cron notation * * * * *.


  • Redis 2.4 or greater is required.
  • Sidekiq 2.13.1 or grater is required.


$ gem install sidekiq-cron

or add to your Gemfile

gem "sidekiq-cron", "~> 0.1.0"

Getting Started

If you are not using Rails you need to add require 'sidekiq-cron' somewhere after require 'sidekiq'.

Job properties:

 'name'  => 'name_of_job', #must be uniq!
 'cron'  => '1 * * * *',
 'klass' => 'MyClass',
 'queue' => 'name of queue',
 'args'  => '[Array or Hash] of arguments hich will be passed to perform method'

Adding Cron job:

class HardWorker
  include Sidekiq::Worker
  def perform(name, count)
    # do something

Sidekiq::Cron::Job.create( name: 'Hard worker - every 5min', cron: '*/5 * * * *', klass: 'HardWorker')
# => true

create method will return only true/false if job was saved or not.

job = name: 'Hard worker - every 5min', cron: '*/5 * * * *', klass: 'HardWorker')

if job.valid?
  puts job.errors

#or simple

  puts job.errors #will return array of errors

Load more jobs from hash: ```ruby

hash = { 'name_of_job' => { 'class' => 'MyClass', 'cron' => '1 * * * ', 'args' => '(OPTIONAL) [Array or Hash]' }, 'My super iber cool job' => { 'class' => 'SecondClass', 'cron' => '/5 * * * *' } }

Sidekiq::Cron::Job.load_from_hash hash ```

Load more jobs from array: ```ruby array = [ { 'name' => 'name_of_job', 'class' => 'MyClass', 'cron' => '1 * * * ', 'args' => '(OPTIONAL) [Array or Hash]' }, { 'name' => 'Cool Job for Second Class', 'class' => 'SecondClass', 'cron' => '/5 * * * *' } ]

Sidekiq::Cron::Job.load_from_array array ```

or from YML (same notation as Resque-scheduler) ```yaml


my_first_job: cron: "*/5 * * * *" class: "HardWorker" queue: hard_worker

second_job: cron: "*/30 * * * *" class: "HardWorker" queue: hard_worker_long args: hard: "stuff" ```

schedule_file = "config/schedule.yml"

if File.exists?(schedule_file)
  Sidekiq::Cron::Job.load_from_hash YAML.load_file(schedule_file)

Finding jobs

#return array of all jobs

#return one job by its uniq name - case sensitive
Sidekiq::Cron::Job.find "Job Name"

#return one job by its uniq name - you can use hash with 'name' key
Sidekiq::Cron::Job.find name: "Job Name"

#if job can't be found nil is returned

Destroy jobs:

#destroys all jobs

#destroy job by its name
Sidekiq::Cron::Job.destroy "Job Name"

#destroy founded job
Sidekiq::Cron::Job.find('Job name').destroy

Work with job:

job = Sidekiq::Cron::Job.find('Job name')

#disable cron scheduling

#enable cron scheduling

#get status of job:
# => enabled/disabled

#enqueue job right now!

How to start scheduling? Just start sidekiq workers by:


Web Ui for Cron Jobs

If you are using sidekiq web ui and you would like to add cron josb to web too, add require 'sidekiq-cron' after require 'sidekiq/web'. By this you will get: Web UI

Contributing to sidekiq-cron

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
  • Fork the project.
  • Start a feature/bugfix branch.
  • Commit and push until you are happy with your contribution.
  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.


Copyright (c) 2013 Ondrej Bartas. See LICENSE.txt for further details.