All Projects → plashchynski → Crono

plashchynski / Crono

Licence: apache-2.0
A time-based background job scheduler daemon (just like Cron) for Rails

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Crono

linda
Linda is a simple dispatcher library.
Stars: ✭ 12 (-98.12%)
Mutual labels:  cron, schedule, scheduler
nodejs-cron-job-must-know
it is an example of running node.js script with every certain period(cron job)
Stars: ✭ 35 (-94.51%)
Mutual labels:  cron, schedule, scheduler
croner
Trigger functions and/or evaluate cron expressions in JavaScript. No dependencies. Most features. All environments.
Stars: ✭ 169 (-73.47%)
Mutual labels:  cron, schedule, scheduler
scheduler
Task Scheduler for Laravel applications. UI from scratch
Stars: ✭ 18 (-97.17%)
Mutual labels:  cron, schedule, scheduler
Gocron
Easy and fluent Go cron scheduling. This is a fork from https://github.com/jasonlvhit/gocron
Stars: ✭ 605 (-5.02%)
Mutual labels:  scheduler, cron, schedule
gronx
Lightweight, fast and dependency-free Cron expression parser (due checker), task scheduler and/or daemon for Golang (tested on v1.13 and above) and standalone usage
Stars: ✭ 206 (-67.66%)
Mutual labels:  daemon, scheduler
ckron
🐋 A cron-like job scheduler for docker
Stars: ✭ 37 (-94.19%)
Mutual labels:  cron, scheduler
schedule-rs
An in-process scheduler for periodic jobs. Schedule lets you run Rust functions on a cron-like schedule.
Stars: ✭ 93 (-85.4%)
Mutual labels:  cron, schedule
sidecloq
Recurring / Periodic / Scheduled / Cron job extension for Sidekiq
Stars: ✭ 81 (-87.28%)
Mutual labels:  cron, schedule
jquery-schedule
jQuery Schedule
Stars: ✭ 53 (-91.68%)
Mutual labels:  schedule, scheduler
asparagus
An easy to use task scheduler for distributed systems
Stars: ✭ 14 (-97.8%)
Mutual labels:  cron, scheduler
krolib
Magic library and DSL to handle complex schedules
Stars: ✭ 19 (-97.02%)
Mutual labels:  schedule, scheduler
Automation-using-Shell-Scripts
Development Automation using Shell Scripting.
Stars: ✭ 41 (-93.56%)
Mutual labels:  cron, scheduler
coo
Schedule Twitter updates with easy
Stars: ✭ 44 (-93.09%)
Mutual labels:  schedule, scheduler
josk
🏃🤖 Scheduler and manager for jobs and tasks in node.js on multi-server and clusters setup
Stars: ✭ 27 (-95.76%)
Mutual labels:  cron, scheduler
cron-schedule
A zero-dependency cron parser and scheduler for Node.js, Deno and the browser.
Stars: ✭ 28 (-95.6%)
Mutual labels:  cron, schedule
Xxl Job
A distributed task scheduling framework.(分布式任务调度平台XXL-JOB)
Stars: ✭ 20,197 (+3070.64%)
Mutual labels:  scheduler, schedule
rhythm
Time-based job scheduler for Apache Mesos
Stars: ✭ 30 (-95.29%)
Mutual labels:  cron, scheduler
gymbox-bot
Simplify the booking of a gymbox class.
Stars: ✭ 21 (-96.7%)
Mutual labels:  cron, schedule
php-cron-expr
Ultra lightweight, Dependency free and Super Fast Cron Expression parser for PHP
Stars: ✭ 42 (-93.41%)
Mutual labels:  cron, scheduler

Crono — Job scheduler for Rails

Gem Version Build Status Code Climate security

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

The Purpose

Currently, there is no such thing as Ruby Cron for Rails. Well, there's Whenever but it works on top of Unix Cron, so you can't manage 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 states to your database using Active Record. You have full control of jobs performing process. It's Ruby, so you can understand and modify it to fit your needs.

Web UI

Requirements

Tested with latest MRI Ruby 2.2+, 2.3+, Rails 4.*, and Rails 5.*. 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 requirement is that the perform method should take no arguments.

Here's an example of a 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 are 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:

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

Here's an example of a Rake Task within a job:

# config/cronotab.rb
require 'rake'

Rails.app_class.load_tasks

class Test
  def perform
    Rake::Task['crono:hello'].invoke
  end
end

Crono.perform(Test).every 5.seconds

With the rake task of:

# lib/tasks/test.rake
namespace :crono do
  desc 'Update all tables'
  task :hello => :environment do
    puts "hello"
  end
end

Please note that crono uses threads, so your code should be thread-safe

Job Schedule

Schedule list is defined in the file config/cronotab.rb, that created using crono:install. The semantic is pretty straightforward:

# config/cronotab.rb
Crono.perform(TestJob).every 2.days, at: {hour: 15, min: 30}
Crono.perform(TestJob).every 1.week, on: :monday, at: "15:30"

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

Crono.perform(TestJob).every 1.week, on: :monday
Crono.perform(TestJob).every 1.week, on: :thursday

The at can be a Hash:

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

You can schedule a job with arguments, which can contain objects that can be serialized using JSON.generate

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

You can set some options that not passed to the job but affect how the job will be treated by Crono. For example, you can set to truncate job logs (which stored in the database) to a certain number of records:

Crono.perform(TestJob).with_options(truncate_log: 100).every 1.week, on: :monday

Run

To run Crono, in your Rails project root directory:

bundle exec crono RAILS_ENV=development

crono usage:

Usage: crono [options] [start|stop|restart|run]
    -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               Deprecated! use --piddir with --process_name; Path to pidfile (Default: )
    -D, --piddir PATH                Path to piddir (Default: tmp/pids)
    -N, --process_name NAME          Name of the process (Default: crono)
    -d, --[no-]daemonize             Deprecated! Instead use crono [start|stop|restart] without this option; Daemonize process (Default: false)
    -m, --monitor                    Start monitor process for a deamon (Default false)
    -e, --environment ENV            Application environment (Default: development)

Run as a daemon

To run Crono as a daemon, please add to your Gemfile:

gem 'daemons'

Then:

bundle install; bundle exec crono start RAILS_ENV=development

There are "start", "stop", and "restart" commands.

Web UI

Crono comes with a Sinatra application that can display the current state of Crono jobs.
Add sinatra and haml to your Gemfile

gem 'haml'
gem 'sinatra', require: nil

Add the following to your config/routes.rb:

Rails.application.routes.draw do
    mount Crono::Web, at: '/crono'
    ...

Access management and other questions described in the wiki.

Known issues

For Rails 5, in case of the errors:

`require': cannot load such file -- rack/showexceptions (LoadError)

See the related issue #52

Capistrano

Use the capistrano-crono gem (github).

Support

Feel free to create issues

Known Issues

License

Please see LICENSE for licensing details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].