Skip to content

discourse/mini_scheduler

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Folders and files

NameName
Last commit message
Last commit date
Nov 15, 2023
Jun 24, 2019
Nov 15, 2023
Nov 15, 2023
Nov 8, 2022
Jul 9, 2018
Oct 15, 2020
May 17, 2023
Nov 8, 2022
Oct 15, 2020
Jan 4, 2023
Nov 8, 2022
Dec 18, 2023

Repository files navigation

Build Status Gem Version

MiniScheduler

MiniScheduler adds recurring jobs to Sidekiq.

Installation

Add this line to your application's Gemfile:

gem 'mini_scheduler'

And then execute:

$ bundle

Or install it yourself as:

$ gem install mini_scheduler

In a Rails application, create files needed in your application to configure mini_scheduler:

$ bin/rails g mini_scheduler:install
$ bin/rails db:migrate

An initializer is created named config/initializers/mini_scheduler.rb which lists all the configuration options.

Configuring MiniScheduler

By default each instance of MiniScheduler will run with a single worker. To amend this behavior:

if Sidekiq.server? && defined?(Rails)
  Rails.application.config.after_initialize do
    MiniScheduler.start(workers: 5)
  end
end

This is useful for cases where you have extremely long running tasks that you would prefer did not starve.

Usage

Create jobs with a recurring schedule like this:

class MyHourlyJob
  include Sidekiq::Worker
  extend MiniScheduler::Schedule

  every 1.hour

  def execute(args)
    # some tasks
  end
end

Options for schedules:

  • queue followed by a queue name, like "queue :email", default queue is "default"
  • every followed by a duration in seconds, like "every 1.hour".
  • daily at: followed by a duration since midnight, like "daily at: 12.hours", to run only once per day at a specific time.

To view the scheduled jobs, their history, and the schedule, go to sidekiq's web UI and look for the "Scheduler" tab at the top.

To enable this view in Sidekiq, add require "mini_scheduler/web" to routes.rb:

require "sidekiq/web"
require "mini_scheduler/web"

Rails.application.routes.draw do
 ...
end

How to reach us

If you have questions about using mini_scheduler or found a problem, you can find us at https://meta.discourse.org.