Skip to content
This repository has been archived by the owner on Oct 24, 2023. It is now read-only.

Pluvie/rails-scheduler

Repository files navigation

Scheduler

This gem aims to create a simple yet efficient framework to handle job scheduling and execution. Currently it supports only MongoDB as database.

Installation

Add this line to your application's Gemfile:

gem 'scheduler'

And then execute:

$ bundle install

And then install the config file with:

$ rails generate scheduler:config

Usage

This gem adds a Scheduler module which can be started, stopped or restarted with their corresponding rake task:

$ rails scheduler:start
$ rails scheduler:stop
$ rails scheduler:restart

A Scheduler is a process that keeps running looking for jobs to perform. The jobs are documents of a specific collection that you can specify in the scheduler configuration file. You can specify your own model to act as a schedulable entity, as long as it includes the Schedulable module. The other configuration options are explained in the generated config/initializers/scheduler.rb file.

This gem also gives you a base ActiveJob implementation, called SchedulerJob, which you can subclass in order to implement your jobs.

As an example, the gem comes with a ExampleSchedulableModel which is a bare class that just includes the Schedulable module, and also an ExampleSchedulerJob job which is a bare implementation of the SchedulableJob job that just sleeps for a given amount of time.

First start by running the scheduler:

$ rails scheduler:start

You can then queue or run jobs by calling:

ExampleSchedulableModel.perform_later('ExampleSchedulableJob', 10) # to queue
ExampleSchedulableModel.perform_now('ExampleSchedulableJob', 10) # to perform immediately

Both methods create a document of ExampleSchedulableModel and put it in queue. The perform_now method skips the scheduler and performs the job immediately, instead the perform_later leaves the performing task to the scheduler.

License

The gem is available as open source under the terms of the MIT License.

About

A Rails engine to schedule jobs, handle parallel execution and manage the jobs queue.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published