Repository is archived
No release in over 3 years
Low commit activity in last 3 years
A gem to schedule jobs, handle parallel execution and manage the jobs queue.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.0
~> 10.0
~> 3.0

Runtime

 Project Readme

Scheduler

This gem aims to create a simple yet efficient framework to handle job scheduling and execution. It is targeted for MongoDB database.

Installation

Add this line to your application's Gemfile:

gem 'mongodb-scheduler'

And then execute:

$ bundle install

Usage

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

$ scheduler start
$ scheduler stop
$ 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 template file lib/scheduler/templates/scheduler.rb file.

As an example, the gem comes with a Scheduler::Examples::SchedulableModel which is a bare class that just includes the Scheduler::Schedulable module, and also an Scheduler::Examples::ExecutableClass class which is a bare implementation of an executable class. An executable class is just a plain Ruby class which must implement a call method which accepts the same arguments that you passed to the schedulable model attribute args. Also, the executable class, must have the first argument of its initialize method to accept the current instance of the schedulable model.

First start by running the scheduler:

$ scheduler start

You can then queue jobs by calling:

YourSchedulableModel.schedule('YourExecutableClass', args...) # to queue

Both methods create a document of YourSchedulableModel 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.

If you want to stop the scheduler, just run:

$ scheduler stop

License

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