Compare commits

..

15 Commits

Author SHA1 Message Date
Dzmitry Plashchynski
8c998794b4 Bump 1.0.1 2016-06-24 13:36:20 +03:00
Dzmitry Plashchynski
de070d5bfa Fix job saving 2016-06-24 13:33:57 +03:00
Dzmitry Plashchynski
e1c143db60 Fix typo 2016-06-24 02:43:15 +03:00
Dzmitry Plashchynski
ad6d6cf9d6 Exclude ruby-2.3 from osx since it isn't installed on Travis 2016-06-24 02:41:10 +03:00
Dzmitry Plashchynski
01cc0864f2 Fix README grammar 2016-06-24 02:23:12 +03:00
Dzmitry Plashchynski
87deadf00e Update gems 2016-06-24 02:17:29 +03:00
Dzmitry Plashchynski
3e5ff2871d Add ruby 2.3 to test on Travis 2016-06-24 02:16:24 +03:00
Dzmitry Plashchynski
b2f107f83f Fix Travis build 2016-06-24 02:10:13 +03:00
Dzmitry Plashchynski
33867f1a25 Merge pull request #47 from adamico/master
Fix for Rails 5
2016-04-18 03:00:35 +03:00
Andrea D'Amico
f240036fcd Fix for Rails 5 2016-04-14 16:16:05 +02:00
Dzmitry Plashchynski
fa69ed0fd9 Bump version to 1.0.0 2016-03-30 16:41:31 +03:00
Dzmitry Plashchynski
95d8e13563 Update gems 2016-03-30 16:40:29 +03:00
Dzmitry Plashchynski
63283509cb Update gems 2016-01-29 18:08:14 +02:00
Dzmitry Plashchynski
16ca450033 Fix option parser 2016-01-20 20:41:26 +02:00
Dzmitry Plashchynski
acbfea2308 Bump 1.0.0.pre2 2016-01-20 16:20:59 +02:00
10 changed files with 57 additions and 37 deletions

View File

@@ -6,10 +6,15 @@ rvm:
- 2.0.0
- 2.1.7
- 2.2.3
- 2.3.1
matrix:
exclude:
- rvm: 2.3.1
os: osx
notifications:
webhooks:
urls:
- https://webhooks.gitter.im/e/907e95dada362be2a13c
on_success: change # options: [always|never|change] default: always
on_failure: always # options: [always|never|change] default: always
on_start: false # default: false
on_start: never # options: [always|never|change] default: always

View File

@@ -1,21 +1,21 @@
PATH
remote: .
specs:
crono (1.0.0.pre)
activerecord (~> 4.0)
activesupport (~> 4.0)
crono (1.0.1)
activerecord (>= 4.0)
activesupport (>= 4.0)
GEM
remote: https://rubygems.org/
specs:
activemodel (4.2.5)
activesupport (= 4.2.5)
activemodel (4.2.6)
activesupport (= 4.2.6)
builder (~> 3.1)
activerecord (4.2.5)
activemodel (= 4.2.5)
activesupport (= 4.2.5)
activerecord (4.2.6)
activemodel (= 4.2.6)
activesupport (= 4.2.6)
arel (~> 6.0)
activesupport (4.2.5)
activesupport (4.2.6)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
@@ -23,14 +23,14 @@ GEM
tzinfo (~> 1.1)
arel (6.0.3)
builder (3.2.2)
byebug (8.2.1)
byebug (9.0.5)
daemons (1.2.3)
diff-lcs (1.2.5)
haml (4.0.7)
tilt
i18n (0.7.0)
json (1.8.3)
minitest (5.8.3)
minitest (5.9.0)
rack (1.6.4)
rack-protection (1.5.3)
rack
@@ -41,7 +41,7 @@ GEM
rspec-core (~> 3.4.0)
rspec-expectations (~> 3.4.0)
rspec-mocks (~> 3.4.0)
rspec-core (3.4.1)
rspec-core (3.4.4)
rspec-support (~> 3.4.0)
rspec-expectations (3.4.0)
diff-lcs (>= 1.2.0, < 2.0)
@@ -50,14 +50,14 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.4.0)
rspec-support (3.4.1)
sinatra (1.4.6)
rack (~> 1.4)
sinatra (1.4.7)
rack (~> 1.5)
rack-protection (~> 1.4)
tilt (>= 1.3, < 3)
sqlite3 (1.3.11)
thread_safe (0.3.5)
tilt (2.0.2)
timecop (0.8.0)
timecop (0.8.1)
tzinfo (1.2.2)
thread_safe (~> 0.1)

View File

@@ -11,14 +11,14 @@ Crono is a time-based background job scheduler daemon (just like Cron) for Ruby
## The Purpose
Currently there is no such thing as Ruby Cron for Rails. Well, there's [Whenever](https://github.com/javan/whenever) but it works on top of Unix Cron, so you haven't 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 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.
Currently, there is no such thing as Ruby Cron for Rails. Well, there's [Whenever](https://github.com/javan/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](https://github.com/plashchynski/crono/raw/master/examples/crono_web_ui.png)
## Requirements
Tested with latest MRI Ruby (2.2, 2.1 and 2.0) and Rails 3.2+
Tested with latest MRI Ruby (2.3, 2.2, 2.1 and 2.0) and Rails 3.2+
Other versions are untested but might work fine.
@@ -47,7 +47,7 @@ Now you are ready to move forward to create a job and schedule it.
#### Create Job
Crono can use Active Job jobs from `app/jobs/`. The only requirements is that the `perform` method should take no arguments.
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:
@@ -61,7 +61,7 @@ class TestJob < ActiveJob::Base
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`:
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`:
```ruby
class TestJob # This is not an Active Job job, but pretty legal Crono job.
@@ -111,7 +111,7 @@ 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:
You can schedule one job a few times if you want the job to be performed a few times a day or a week:
```ruby
Crono.perform(TestJob).every 1.week, on: :monday
@@ -131,23 +131,38 @@ serialized using JSON.generate
Crono.perform(TestJob, 'some', 'args').every 1.day, at: {hour: 12, min: 15}
```
#### Run daemon
#### Run
To run Crono daemon, in your Rails project root directory:
To run Crono, in your Rails project root directory:
bundle exec crono RAILS_ENV=development
crono usage:
```
Usage: crono [options] start|stop|restart|run
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)
--piddir PATH Path to piddir (Default: tmp/pids)
-N, --process_name name Name of the process (Default: crono)
-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)
-e, --environment ENV Application environment (Default: development)
```
#### Run as a daemon
To run Crono as a daemon, please add to your Gemfile:
```ruby
gem 'daemons'
```
Then:
bundle install; bundle exec crono start RAILS_ENV=development
There are "start", "stop", and "restart" commands.
## Web UI

View File

@@ -19,8 +19,8 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']
spec.add_runtime_dependency 'activesupport', '~> 4.0'
spec.add_runtime_dependency 'activerecord', '~> 4.0'
spec.add_runtime_dependency 'activesupport', '>= 4.0'
spec.add_runtime_dependency 'activerecord', '>= 4.0'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'bundler', '>= 1.0.0'
spec.add_development_dependency 'rspec', '~> 3.0'

View File

@@ -1,3 +1,5 @@
Thread.abort_on_exception = true
require 'crono'
require 'optparse'
@@ -122,7 +124,7 @@ module Crono
def parse_options(argv)
@argv = OptionParser.new do |opts|
opts.banner = "Usage: crono [options] start|stop|restart|run"
opts.banner = "Usage: crono [options] [start|stop|restart|run]"
opts.on("-C", "--cronotab PATH", "Path to cronotab file (Default: #{config.cronotab})") do |cronotab|
config.cronotab = cronotab
@@ -136,7 +138,7 @@ module Crono
config.pidfile = pidfile
end
opts.on("--piddir PATH", "Path to piddir (Default: #{config.piddir})") do |piddir|
opts.on("-D", "--piddir PATH", "Path to piddir (Default: #{config.piddir})") do |piddir|
config.piddir = piddir
end

View File

@@ -65,7 +65,7 @@ module Crono
saved_log = model.reload.log || ''
log_to_save = saved_log + job_log.string
model.update(last_performed_at: last_performed_at, log: log_to_save,
healthy: healthy, args: job_args)
healthy: healthy)
end
def perform_job

View File

@@ -1,3 +1,3 @@
module Crono
VERSION = '1.0.0.pre'
VERSION = '1.0.1'
end

View File

@@ -5,7 +5,6 @@ class CreateCronoJobs < ActiveRecord::Migration
t.text :log
t.datetime :last_performed_at
t.boolean :healthy
t.text :args
t.timestamps null: false
end
add_index :crono_jobs, [:job_id], unique: true

View File

@@ -105,7 +105,6 @@ describe Crono::Job do
@crono_job = Crono::CronoJob.find_by(job_id: job.job_id)
expect(@crono_job.last_performed_at.utc.to_s).to be_eql job.last_performed_at.utc.to_s
expect(@crono_job.healthy).to be true
expect(@crono_job.args).to eq '[{"some":"data"}]'
end
it 'should save and truncate job log' do

View File

@@ -61,14 +61,14 @@ describe Crono::Period do
time = 10.minutes.ago
at = [time.hour, time.min].join(':')
@period = Crono::Period.new(2.days, at: at)
expect(@period.next).to be_eql(2.days.from_now.change(hour: time.hour, min: time.min))
expect(@period.next.to_s).to be_eql(2.days.from_now.change(hour: time.hour, min: time.min).to_s)
end
it "should set time to 'at' time as a hash" do
time = 10.minutes.ago
at = { hour: time.hour, min: time.min }
@period = Crono::Period.new(2.days, at: at)
expect(@period.next).to be_eql(2.days.from_now.change(at))
expect(@period.next.to_s).to be_eql(2.days.from_now.change(at).to_s)
end
it "should raise error when 'at' is wrong" do