Dzmitry Plashchynski 186fe43fc0 Bump version 0.6.1
2015-03-07 01:39:32 +02:00
2015-03-06 22:33:13 +02:00
2015-03-05 15:13:48 +02:00
2015-03-07 01:39:32 +02:00
2015-03-07 01:29:16 +02:00
2015-03-01 14:06:05 +02:00
2015-03-01 14:47:56 +02:00
2015-03-03 20:13:07 +02:00
2015-03-07 01:39:32 +02:00
2015-03-01 14:07:08 +02:00
2015-03-07 01:39:32 +02:00
2015-03-03 15:45:07 +02:00
2015-03-03 15:45:07 +02:00
2015-03-02 01:08:18 +02:00
2015-03-07 01:29:16 +02:00

Crono — Job scheduler for Rails

Gem Version Build Status Code Climate security Join the chat at https://gitter.im/plashchynski/crono

Crono is a time-based background job scheduler daemon (just like Cron) for Ruby on Rails.

The Idea

Currently there is no such thing as Cron in Ruby for Rails. Well, there's Whenever but it works on top of Unix Cron, so you have no total control of it from Ruby. Crono is pure Ruby. It doesn't use Unix Cron and other platform-dependent things. So you can use it on all platforms supported by Ruby. It persists job state to your database using Active Record. You have full control of jobs performing process. You have Ruby code, so you can understand and modify it to fit your needs.

Requirements

Tested with latest MRI Ruby (2.2, 2.1 and 2.0) and Rails 3.2+
Other versions are untested but might work fine.

Installation

Add the following line to your application's Gemfile:

gem 'crono'

Run the bundle command to install it.
After you install Crono, you can run the generator:

rails generate crono:install

It will create a configuration file config/cronotab.rb and migration
Run the migration:

rake db:migrate

Now you are ready to move forward to create a job and schedule it.

Usage

Create Job

Crono can use Active Job jobs from app/jobs/. The only requirements is that the perform method should take no arguments.

Here's an example of a test job:

# app/jobs/test_job.rb
class TestJob < ActiveJob::Base
  def perform
    # put you scheduled code here
    # Comments.deleted.clean_up...
  end
end

The ActiveJob jobs is convenient because you can use one job in both periodic and enqueued ways. But Active Job is not required. Any class can be used as a crono job if it implements a method perform without arguments:

class TestJob # This is not an Active Job job, but pretty legal Crono job.
  def perform
    # put you scheduled code here
    # Comments.deleted.clean_up...
  end
end

Job Schedule

The schedule described in the configuration file config/cronotab.rb, that created using crono:install or manually. The semantic is pretty straightforward:

# config/cronotab.rb
Crono.perform(TestJob).every 2.days, at: "15:30"

You can schedule one job a few times, if you want a job to be performed a few times a day:

Crono.perform(TestJob).every 1.day, at: "00:00"
Crono.perform(TestJob).every 1.day, at: "12:00"

The at can be a Hash:

Crono.perform(TestJob).every 1.day, at: {hour: 12, min: 15}

Run daemon

To run Crono daemon, in your Rails project root directory:

bundle exec crono RAILS_ENV=development

crono usage:

Usage: crono [options]
    -C, --cronotab PATH              Path to cronotab file (Default: config/cronotab.rb)
    -L, --logfile PATH               Path to writable logfile (Default: log/crono.log)
    -P, --pidfile PATH               Path to pidfile (Default: tmp/pids/crono.pid)
    -d, --[no-]daemonize             Daemonize process (Default: false)
    -e, --environment ENV            Application environment (Default: development)

Capistrano

Use the capistrano-crono gem (github).

Support

Feel free to create issues

License

Please see LICENSE for licensing details.

Description
No description provided
Readme Apache-2.0 1.9 MiB
Latest
2024-12-18 12:58:42 +01:00
Languages
Ruby 93.5%
HTML 5.9%
CSS 0.6%