crono 1.0.3 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +2 -8
- data/Changes.md +10 -0
- data/Gemfile.lock +26 -26
- data/README.md +17 -4
- data/lib/crono/cli.rb +9 -6
- data/lib/crono/job.rb +10 -3
- data/lib/crono/performer_proxy.rb +6 -1
- data/lib/crono/period.rb +2 -0
- data/lib/crono/version.rb +1 -1
- data/lib/generators/crono/install/templates/migrations/create_crono_jobs.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca06047f3fd1428fe8babcee91ca5a1e1ff9e326
|
4
|
+
data.tar.gz: 8f1a48db399615c5a3d8641f194273a3a82ef9cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d12831d9d1f5bae9801491cce5c4039049f4cefebd0b23b5b33050916ae9e42af2623ca66476f2f2b3eb0204d39296f74079b85492f3fa3cca016ff7cbd8b585
|
7
|
+
data.tar.gz: 35baf793c81867128dd577c10b19cb273ad2c15d34987903fb3f9bfe0dc0e5e69e4d27d642b67a2afee8b5c5129b7cfb5f72c0cd7417404934ef6ca8593ad938
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Changes.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
1.1.0
|
2
|
+
-----------
|
3
|
+
- Rails 3 and old Rubies are not supported anymore, sorry rails 3 guys...
|
4
|
+
- Requires Ruby 2.2.2 or newer
|
5
|
+
- Fixed crash when no jobs defined in your cronotab
|
6
|
+
- Some doc updates (thanks to @pachacamac)
|
7
|
+
- Job will schedule on: today if at: time not passed (thanks to @acolyer)
|
8
|
+
- Job log truncating (thanks to @reiz)
|
9
|
+
|
10
|
+
|
1
11
|
1.0.3
|
2
12
|
-----------
|
3
13
|
- "every 1 week" jobs now displaying on Rails 5 as "1 week" not as "7 days"
|
data/Gemfile.lock
CHANGED
@@ -1,57 +1,57 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
crono (1.0
|
4
|
+
crono (1.1.0)
|
5
5
|
activerecord (>= 4.0)
|
6
6
|
activesupport (>= 4.0)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activemodel (5.0.0)
|
12
|
-
activesupport (= 5.0.0)
|
13
|
-
activerecord (5.0.0)
|
14
|
-
activemodel (= 5.0.0)
|
15
|
-
activesupport (= 5.0.0)
|
11
|
+
activemodel (5.0.0.1)
|
12
|
+
activesupport (= 5.0.0.1)
|
13
|
+
activerecord (5.0.0.1)
|
14
|
+
activemodel (= 5.0.0.1)
|
15
|
+
activesupport (= 5.0.0.1)
|
16
16
|
arel (~> 7.0)
|
17
|
-
activesupport (5.0.0)
|
17
|
+
activesupport (5.0.0.1)
|
18
18
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
19
19
|
i18n (~> 0.7)
|
20
20
|
minitest (~> 5.1)
|
21
21
|
tzinfo (~> 1.1)
|
22
|
-
arel (7.
|
23
|
-
byebug (9.0.
|
22
|
+
arel (7.1.4)
|
23
|
+
byebug (9.0.6)
|
24
24
|
concurrent-ruby (1.0.2)
|
25
|
-
daemons (1.2.
|
25
|
+
daemons (1.2.4)
|
26
26
|
diff-lcs (1.2.5)
|
27
27
|
haml (4.0.7)
|
28
28
|
tilt
|
29
29
|
i18n (0.7.0)
|
30
|
-
minitest (5.9.
|
31
|
-
rack (1.6.
|
30
|
+
minitest (5.9.1)
|
31
|
+
rack (1.6.5)
|
32
32
|
rack-protection (1.5.3)
|
33
33
|
rack
|
34
34
|
rack-test (0.6.3)
|
35
35
|
rack (>= 1.0)
|
36
|
-
rake (11.
|
37
|
-
rspec (3.
|
38
|
-
rspec-core (~> 3.
|
39
|
-
rspec-expectations (~> 3.
|
40
|
-
rspec-mocks (~> 3.
|
41
|
-
rspec-core (3.
|
42
|
-
rspec-support (~> 3.
|
43
|
-
rspec-expectations (3.
|
36
|
+
rake (11.3.0)
|
37
|
+
rspec (3.5.0)
|
38
|
+
rspec-core (~> 3.5.0)
|
39
|
+
rspec-expectations (~> 3.5.0)
|
40
|
+
rspec-mocks (~> 3.5.0)
|
41
|
+
rspec-core (3.5.4)
|
42
|
+
rspec-support (~> 3.5.0)
|
43
|
+
rspec-expectations (3.5.0)
|
44
44
|
diff-lcs (>= 1.2.0, < 2.0)
|
45
|
-
rspec-support (~> 3.
|
46
|
-
rspec-mocks (3.
|
45
|
+
rspec-support (~> 3.5.0)
|
46
|
+
rspec-mocks (3.5.0)
|
47
47
|
diff-lcs (>= 1.2.0, < 2.0)
|
48
|
-
rspec-support (~> 3.
|
49
|
-
rspec-support (3.
|
48
|
+
rspec-support (~> 3.5.0)
|
49
|
+
rspec-support (3.5.0)
|
50
50
|
sinatra (1.4.7)
|
51
51
|
rack (~> 1.5)
|
52
52
|
rack-protection (~> 1.4)
|
53
53
|
tilt (>= 1.3, < 3)
|
54
|
-
sqlite3 (1.3.
|
54
|
+
sqlite3 (1.3.12)
|
55
55
|
thread_safe (0.3.5)
|
56
56
|
tilt (2.0.5)
|
57
57
|
timecop (0.8.1)
|
@@ -75,4 +75,4 @@ DEPENDENCIES
|
|
75
75
|
timecop (>= 0.7)
|
76
76
|
|
77
77
|
BUNDLED WITH
|
78
|
-
1.
|
78
|
+
1.13.6
|
data/README.md
CHANGED
@@ -4,7 +4,6 @@ Crono — Job scheduler for Rails
|
|
4
4
|
[![Build Status](https://travis-ci.org/plashchynski/crono.svg?branch=master)](https://travis-ci.org/plashchynski/crono)
|
5
5
|
[![Code Climate](https://codeclimate.com/github/plashchynski/crono/badges/gpa.svg)](https://codeclimate.com/github/plashchynski/crono)
|
6
6
|
[![security](https://hakiri.io/github/plashchynski/crono/master.svg)](https://hakiri.io/github/plashchynski/crono/master)
|
7
|
-
[![Join the chat at https://gitter.im/plashchynski/crono](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/plashchynski/crono?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
8
7
|
|
9
8
|
Crono is a time-based background job scheduler daemon (just like Cron) for Ruby on Rails.
|
10
9
|
|
@@ -18,7 +17,7 @@ Currently, there is no such thing as Ruby Cron for Rails. Well, there's [Wheneve
|
|
18
17
|
|
19
18
|
## Requirements
|
20
19
|
|
21
|
-
Tested with latest MRI Ruby
|
20
|
+
Tested with latest MRI Ruby 2.2+, 2.3+, Rails 4.\*, and Rails 5.\*.
|
22
21
|
Other versions are untested but might work fine.
|
23
22
|
|
24
23
|
|
@@ -77,8 +76,8 @@ Here's an example of a Rake Task within a job:
|
|
77
76
|
```ruby
|
78
77
|
# config/cronotab.rb
|
79
78
|
require 'rake'
|
80
|
-
|
81
|
-
|
79
|
+
|
80
|
+
Rails.app_class.load_tasks
|
82
81
|
|
83
82
|
class Test
|
84
83
|
def perform
|
@@ -131,6 +130,12 @@ serialized using JSON.generate
|
|
131
130
|
Crono.perform(TestJob, 'some', 'args').every 1.day, at: {hour: 12, min: 15}
|
132
131
|
```
|
133
132
|
|
133
|
+
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:
|
134
|
+
|
135
|
+
```ruby
|
136
|
+
Crono.perform(TestJob).with_options(truncate_log: 100).every 1.week, on: :monday
|
137
|
+
```
|
138
|
+
|
134
139
|
#### Run
|
135
140
|
|
136
141
|
To run Crono, in your Rails project root directory:
|
@@ -184,6 +189,14 @@ Rails.application.routes.draw do
|
|
184
189
|
|
185
190
|
Access management and other questions described in the [wiki](https://github.com/plashchynski/crono/wiki/Web-UI).
|
186
191
|
|
192
|
+
#### Known issues
|
193
|
+
|
194
|
+
For Rails 5, in case of the errors:
|
195
|
+
```
|
196
|
+
`require': cannot load such file -- rack/showexceptions (LoadError)
|
197
|
+
```
|
198
|
+
See the related issue [#52](https://github.com/plashchynski/crono/issues/52)
|
199
|
+
|
187
200
|
|
188
201
|
## Capistrano
|
189
202
|
|
data/lib/crono/cli.rb
CHANGED
@@ -29,7 +29,11 @@ module Crono
|
|
29
29
|
Cronotab.process(File.expand_path(config.cronotab))
|
30
30
|
print_banner
|
31
31
|
|
32
|
-
|
32
|
+
unless have_jobs?
|
33
|
+
logger.error "You have no jobs in you cronotab file #{config.cronotab}"
|
34
|
+
return
|
35
|
+
end
|
36
|
+
|
33
37
|
if config.daemonize
|
34
38
|
start_working_loop_in_daemon
|
35
39
|
else
|
@@ -39,6 +43,10 @@ module Crono
|
|
39
43
|
|
40
44
|
private
|
41
45
|
|
46
|
+
def have_jobs?
|
47
|
+
Crono.scheduler.jobs.present?
|
48
|
+
end
|
49
|
+
|
42
50
|
def setup_log
|
43
51
|
if config.daemonize
|
44
52
|
self.logfile = config.logfile
|
@@ -85,11 +93,6 @@ module Crono
|
|
85
93
|
::Rails.application.eager_load!
|
86
94
|
end
|
87
95
|
|
88
|
-
def check_jobs
|
89
|
-
return if Crono.scheduler.jobs.present?
|
90
|
-
logger.error "You have no jobs in you cronotab file #{config.cronotab}"
|
91
|
-
end
|
92
|
-
|
93
96
|
def start_working_loop_in_daemon
|
94
97
|
unless ENV['RAILS_ENV'] == 'test'
|
95
98
|
begin
|
data/lib/crono/job.rb
CHANGED
@@ -6,15 +6,16 @@ module Crono
|
|
6
6
|
class Job
|
7
7
|
include Logging
|
8
8
|
|
9
|
-
attr_accessor :performer, :period, :job_args, :last_performed_at,
|
9
|
+
attr_accessor :performer, :period, :job_args, :last_performed_at, :job_options,
|
10
10
|
:next_performed_at, :job_log, :job_logger, :healthy, :execution_interval
|
11
11
|
|
12
|
-
def initialize(performer, period, job_args)
|
12
|
+
def initialize(performer, period, job_args, job_options = {})
|
13
13
|
self.execution_interval = 0.minutes
|
14
14
|
self.performer, self.period = performer, period
|
15
15
|
self.job_args = JSON.generate(job_args)
|
16
16
|
self.job_log = StringIO.new
|
17
17
|
self.job_logger = Logger.new(job_log)
|
18
|
+
self.job_options = job_options
|
18
19
|
self.next_performed_at = period.next
|
19
20
|
@semaphore = Mutex.new
|
20
21
|
end
|
@@ -61,9 +62,15 @@ module Crono
|
|
61
62
|
job_log.truncate(job_log.rewind)
|
62
63
|
end
|
63
64
|
|
65
|
+
def truncate_log(log)
|
66
|
+
return log.lines.last(job_options[:truncate_log]).join if job_options[:truncate_log]
|
67
|
+
return log
|
68
|
+
end
|
69
|
+
|
64
70
|
def update_model
|
65
71
|
saved_log = model.reload.log || ''
|
66
72
|
log_to_save = saved_log + job_log.string
|
73
|
+
log_to_save = truncate_log(log_to_save)
|
67
74
|
model.update(last_performed_at: last_performed_at, log: log_to_save,
|
68
75
|
healthy: healthy)
|
69
76
|
end
|
@@ -98,7 +105,7 @@ module Crono
|
|
98
105
|
|
99
106
|
def log(message, severity = Logger::INFO)
|
100
107
|
@semaphore.synchronize do
|
101
|
-
logger.log
|
108
|
+
logger.log(severity, message) if logger
|
102
109
|
job_logger.log severity, message
|
103
110
|
end
|
104
111
|
end
|
@@ -8,7 +8,7 @@ module Crono
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def every(period, *args)
|
11
|
-
@job = Job.new(@performer, Period.new(period, *args), @job_args)
|
11
|
+
@job = Job.new(@performer, Period.new(period, *args), @job_args, @options)
|
12
12
|
@scheduler.add_job(@job)
|
13
13
|
self
|
14
14
|
end
|
@@ -17,6 +17,11 @@ module Crono
|
|
17
17
|
@job.execution_interval = execution_interval if @job
|
18
18
|
self
|
19
19
|
end
|
20
|
+
|
21
|
+
def with_options(options)
|
22
|
+
@options = options
|
23
|
+
self
|
24
|
+
end
|
20
25
|
end
|
21
26
|
|
22
27
|
def self.perform(performer, *job_args)
|
data/lib/crono/period.rb
CHANGED
@@ -23,6 +23,7 @@ module Crono
|
|
23
23
|
return initial_next unless since
|
24
24
|
@next = @period.since(since)
|
25
25
|
end
|
26
|
+
|
26
27
|
@next = @next.beginning_of_week.advance(days: @on) if @on
|
27
28
|
@next = @next.change(time_atts)
|
28
29
|
return @next if @next.future?
|
@@ -48,6 +49,7 @@ module Crono
|
|
48
49
|
def initial_day
|
49
50
|
return Time.now unless @on
|
50
51
|
day = Time.now.beginning_of_week.advance(days: @on)
|
52
|
+
day = day.change(time_atts)
|
51
53
|
return day if day.future?
|
52
54
|
@period.from_now.beginning_of_week.advance(days: @on)
|
53
55
|
end
|
data/lib/crono/version.rb
CHANGED
@@ -2,7 +2,7 @@ class CreateCronoJobs < ActiveRecord::Migration
|
|
2
2
|
def self.up
|
3
3
|
create_table :crono_jobs do |t|
|
4
4
|
t.string :job_id, null: false
|
5
|
-
t.text :log
|
5
|
+
t.text :log, limit: 4294967295 # LONGTEXT for MySQL
|
6
6
|
t.datetime :last_performed_at
|
7
7
|
t.boolean :healthy
|
8
8
|
t.timestamps null: false
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crono
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dzmitry Plashchynski
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -272,7 +272,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
272
272
|
version: '0'
|
273
273
|
requirements: []
|
274
274
|
rubyforge_project:
|
275
|
-
rubygems_version: 2.
|
275
|
+
rubygems_version: 2.6.8
|
276
276
|
signing_key:
|
277
277
|
specification_version: 4
|
278
278
|
summary: Job scheduler for Rails
|