{"id":18365400,"url":"https://github.com/le0pard/sidekiq-crond","last_synced_at":"2026-02-14T21:31:05.745Z","repository":{"id":136154359,"uuid":"237042260","full_name":"le0pard/sidekiq-crond","owner":"le0pard","description":"Scheduler / Cron for Sidekiq jobs","archived":false,"fork":false,"pushed_at":"2020-02-25T14:31:16.000Z","size":74,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-10T03:35:42.501Z","etag":null,"topics":["cron","crontab","sidekiq","sidekiq-cron","sidekiq-scheduler","sidekiq-web"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/le0pard.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-01-29T17:28:39.000Z","updated_at":"2020-02-25T14:31:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"c9d10757-0970-4afa-97eb-d5319a104269","html_url":"https://github.com/le0pard/sidekiq-crond","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/le0pard/sidekiq-crond","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/le0pard%2Fsidekiq-crond","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/le0pard%2Fsidekiq-crond/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/le0pard%2Fsidekiq-crond/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/le0pard%2Fsidekiq-crond/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/le0pard","download_url":"https://codeload.github.com/le0pard/sidekiq-crond/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/le0pard%2Fsidekiq-crond/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29456211,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-14T21:29:27.764Z","status":"ssl_error","status_checked_at":"2026-02-14T21:28:11.111Z","response_time":53,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cron","crontab","sidekiq","sidekiq-cron","sidekiq-scheduler","sidekiq-web"],"created_at":"2024-11-05T23:13:21.211Z","updated_at":"2026-02-14T21:31:05.733Z","avatar_url":"https://github.com/le0pard.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sidekiq-Crond\n\nA scheduling add-on for [Sidekiq](http://sidekiq.org).\n\nRuns a thread alongside Sidekiq workers to schedule jobs at specified times (using cron notation `* * * * *` parsed by [Fugit](https://github.com/floraison/fugit), more about [cron notation](https://crontab.guru/).\n\nChecks for new jobs to schedule every 30 seconds and doesn't schedule the same job multiple times when more than one Sidekiq worker is running.\n\nScheduling jobs are added only when at least one Sidekiq process is running, but it is safe to use Sidekiq-Crond in environments where multiple Sidekiq processes or nodes are running.\n\nIf you want to know how scheduling work, check out [under the hood](#under-the-hood)\n\nWorks with ActiveJob (Rails 4.2+)\n\nYou don't need Sidekiq PRO, you can use this gem with plain __Sidekiq__.\n\n## Requirements\n\n- Redis 2.8 or greater is required. (Redis 3.0.3 or greater is recommended for large scale use)\n- Sidekiq 5 or greater is required\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'sidekiq-crond'\n```\n\nAnd then execute:\n\n    $ bundle install\n\nOr install it yourself as:\n\n    $ gem install sidekiq-crond\n\n## Usage\n\nIf you are not using Rails, you need to add `require 'sidekiq-crond'` somewhere after `require 'sidekiq'`.\n\n_Job properties_:\n\n```ruby\n{\n 'name'  =\u003e 'name_of_job', #must be uniq!\n 'cron'  =\u003e '1 * * * *',  # execute at 1 minute of every hour, ex: 12:01, 13:01, 14:01, 15:01...etc(HH:MM)\n 'class' =\u003e 'MyClass',\n #OPTIONAL\n 'queue' =\u003e 'name of queue',\n 'args'  =\u003e '[Array or Hash] of arguments which will be passed to perform method',\n 'date_as_argument' =\u003e true, # add the time of execution as last argument of the perform method\n 'active_job' =\u003e true,  # enqueue job through rails 4.2+ active job interface\n 'queue_name_prefix' =\u003e 'prefix', # rails 4.2+ active job queue with prefix\n 'queue_name_delimiter' =\u003e '.',  # rails 4.2+ active job queue with custom delimiter\n 'description' =\u003e 'A sentence describing what work this job performs.'  # Optional\n}\n```\n\n### Time, cron and sidekiq-crond\n\nFor testing your cron notation you can use [crontab.guru](https://crontab.guru).\n\nsidekiq-crond uses [Fugit](https://github.com/floraison/fugit) to parse the cronline.\nIf using Rails, this is evaluated against the timezone configured in Rails, otherwise the default is UTC.\n\nIf you want to have your jobs enqueued based on a different time zone you can specify a timezone in the cronline,\nlike this `'0 22 * * 1-5 America/Chicago'`.\n\nSee [rufus-scheduler documentation](https://github.com/jmettraux/rufus-scheduler#a-note-about-timezones) for more information. (note. Rufus scheduler is using Fugit under the hood, so documentation for Rufus Scheduler can help you also)\n\n### What objects/classes can be scheduled\n#### Sidekiq Worker\nIn this example, we are using `HardWorker` which looks like:\n```ruby\nclass HardWorker\n  include Sidekiq::Worker\n  def perform(*args)\n    # do something\n  end\nend\n```\n\n#### Active Job Worker\nYou can schedule: `ExampleJob` which looks like:\n```ruby\nclass ExampleJob \u003c ActiveJob::Base\n  queue_as :default\n\n  def perform(*args)\n    # Do something\n  end\nend\n```\n\n#### Adding Cron job:\n```ruby\n\nclass HardWorker\n  include Sidekiq::Worker\n  def perform(name, count)\n    # do something\n  end\nend\n\nSidekiq::Crond::Job.create(name: 'Hard worker - every 5min', cron: '*/5 * * * *', class: 'HardWorker') # execute at every 5 minutes, ex: 12:05, 12:10, 12:15...etc\n# =\u003e true\n```\n\n`create` method will return only true/false if job was saved or not.\n\n```ruby\njob = Sidekiq::Crond::Job.new(name: 'Hard worker - every 5min', cron: '*/5 * * * *', class: 'HardWorker')\n\nif job.valid?\n  job.save\nelse\n  puts job.errors\nend\n\n#or simple\n\nunless job.save\n  puts job.errors #will return array of errors\nend\n```\n\nLoad more jobs from hash:\n```ruby\n\nhash = {\n  'name_of_job' =\u003e {\n    'class' =\u003e 'MyClass',\n    'cron'  =\u003e '1 * * * *',\n    'args'  =\u003e '(OPTIONAL) [Array or Hash]'\n  },\n  'My super iber cool job' =\u003e {\n    'class' =\u003e 'SecondClass',\n    'cron'  =\u003e '*/5 * * * *'\n  }\n}\n\nSidekiq::Crond::Job.load_from_hash hash\n```\n\nLoad more jobs from array:\n```ruby\narray = [\n  {\n    'name'  =\u003e 'name_of_job',\n    'class' =\u003e 'MyClass',\n    'cron'  =\u003e '1 * * * *',\n    'args'  =\u003e '(OPTIONAL) [Array or Hash]'\n  },\n  {\n    'name'  =\u003e 'Cool Job for Second Class',\n    'class' =\u003e 'SecondClass',\n    'cron'  =\u003e '*/5 * * * *'\n  }\n]\n\nSidekiq::Crond::Jobs.load_from_array array\n```\n\nBang-suffixed methods will remove jobs that are not present in the given hash/array,\nupdate jobs that have the same names, and create new ones when the names are previously unknown.\n\n```ruby\nSidekiq::Crond::Jobs#load_from_hash! hash\nSidekiq::Crond::Jobs#load_from_array! array\n```\n\nor from YML (same notation as Resque-scheduler)\n\n```yaml\n#config/schedule.yml\n\nmy_first_job:\n  cron: \"*/5 * * * *\"\n  class: \"HardWorker\"\n  queue: hard_worker\n\nsecond_job:\n  cron: \"*/30 * * * *\" # execute at every 30 minutes\n  class: \"HardWorker\"\n  queue: hard_worker_long\n  args:\n    hard: \"stuff\"\n```\n\n```ruby\n#initializers/sidekiq.rb\nschedule_file = \"config/schedule.yml\"\n\nif File.exist?(schedule_file) \u0026\u0026 Sidekiq.server?\n  Sidekiq::Crond::Jobs.load_from_hash YAML.load_file(schedule_file)\nend\n```\n\nor you can use for loading jobs from yml file [sidekiq-cron-tasks](https://github.com/coverhound/sidekiq-cron-tasks) which will add rake task `bundle exec rake sidekiq_cron:load` to your rails application.\n\n#### Finding jobs\n```ruby\n#return array of all jobs\nSidekiq::Crond::Jobs.all\n\n#return one job by its unique name - case sensitive\nSidekiq::Crond::Jobs.find \"Job Name\"\n\n#return one job by its unique name - you can use hash with 'name' key\nSidekiq::Crond::Jobs.find name: \"Job Name\"\n\n#if job can't be found nil is returned\n```\n\n#### Destroy jobs:\n```ruby\n#destroys all jobs\nSidekiq::Crond::Jobs.destroy_all!\n\n#destroy job by its name\nSidekiq::Crond::Jobs.destroy \"Job Name\"\n\n#destroy found job\nSidekiq::Crond::Jobs.find('Job name').destroy\n```\n\n#### Work with job:\n```ruby\njob = Sidekiq::Crond::Jobs.find('Job name')\n\n#disable cron scheduling\njob.disable!\n\n#enable cron scheduling\njob.enable!\n\n#get status of job:\njob.status\n# =\u003e enabled/disabled\n\n#enqueue job right now!\njob.enque!\n```\n\nHow to start scheduling?\nJust start Sidekiq workers by running:\n\n    sidekiq\n\n### Web UI for Cron Jobs\n\nIf you are using Sidekiq's web UI and you would like to add cron jobs too to this web UI,\nadd `require 'sidekiq/crond/web'` after `require 'sidekiq/web'`.\n\n### Forking Processes\n\nIf you're using a forking web server like Unicorn you may run into an issue where the Redis connection is used\nbefore the process forks, causing the following exception\n\n    Redis::InheritedError: Tried to use a connection from a child process without reconnecting. You need to reconnect to Redis after forking.\n\nto occur. To avoid this, wrap your job creation in the call to `Sidekiq.configure_server`:\n\n```ruby\nSidekiq.configure_server do |config|\n  schedule_file = \"config/schedule.yml\"\n\n  if File.exist?(schedule_file)\n    Sidekiq::Crond::Jobs.load_from_hash YAML.load_file(schedule_file)\n  end\nend\n```\n\n## Under the hood\n\nWhen you start the Sidekiq process, it starts one thread with `Sidekiq::Poller` instance, which perform the adding of scheduled jobs to queues, retries etc.\n\nsidekiq-crond adds itself into this start procedure and starts another thread with `Sidekiq::Crond::Poller` which checks all enabled Sidekiq cron jobs every 10 seconds, if they should be added to queue (their cronline matches time of check).\n\nsidekiq-crond is checking jobs to be enqueued every 30s by default, you can change it by setting:\n\n```ruby\nSidekiq.options[:cron_check_interval] = 10\n```\n\nsidekiq-crond is safe to use with multiple sidekiq processes or nodes. It uses a Redis sorted set to determine that only the first process who asks can enqueue scheduled jobs into the queue.\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/le0pard/sidekiq-crond. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/le0pard/sidekiq-crond/blob/master/CODE_OF_CONDUCT.md).\n\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the Sidekiq::Crond project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/le0pard/sidekiq-crond/blob/master/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fle0pard%2Fsidekiq-crond","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fle0pard%2Fsidekiq-crond","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fle0pard%2Fsidekiq-crond/lists"}