crono 0.8.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +6 -2
- data/lib/crono.rb +1 -0
- data/lib/crono/cli.rb +1 -3
- data/lib/crono/job.rb +3 -1
- data/lib/crono/orm/active_record/crono_job.rb +4 -0
- data/lib/crono/railtie.rb +9 -0
- data/lib/crono/scheduler.rb +2 -0
- data/lib/crono/version.rb +1 -1
- data/lib/tasks/crono_tasks.rake +26 -0
- data/spec/assets/bad_cronotab.rb +12 -0
- data/spec/assets/good_cronotab.rb +9 -0
- data/spec/cli_spec.rb +0 -5
- data/spec/job_spec.rb +10 -13
- data/spec/performer_proxy_spec.rb +0 -5
- data/spec/scheduler_spec.rb +0 -5
- data/spec/spec_helper.rb +11 -0
- data/spec/tasks/crono_tasks_spec.rb +23 -0
- data/spec/web_spec.rb +1 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2fe5cc8fdfa89bc633c58c8f83c5c7f324753a97
|
4
|
+
data.tar.gz: 59cd54c8f5dfc6ab98ea2969aab1c9821528e426
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3d4c392b0d88d5c11d5eee6a1a138bfcda13c81369bacfa6400beeb87eef6a38e04184127d6f0f051ecc916ec577d066683a274ae0df2d49f2a75b3745a7ec4
|
7
|
+
data.tar.gz: b2b03f125d780069004609f23dd95b3fb9d044e9aa3003a573a6d61016a6260a20ecdf8ebc6f8157facda0602613d297407c57d11a1bbb3334a63d4f9b8ecb21
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
Crono — Job scheduler for Rails
|
2
2
|
------------------------
|
3
|
-
[](http://badge.fury.io/rb/crono)
|
3
|
+
[](http://badge.fury.io/rb/crono)Here's an example of a test job:
|
4
|
+
|
5
|
+
|
4
6
|
[](https://travis-ci.org/plashchynski/crono)
|
5
7
|
[](https://codeclimate.com/github/plashchynski/crono)
|
6
8
|
[](https://hakiri.io/github/plashchynski/crono/master)
|
@@ -49,7 +51,7 @@ Now you are ready to move forward to create a job and schedule it.
|
|
49
51
|
|
50
52
|
Crono can use Active Job jobs from `app/jobs/`. The only requirements is that the `perform` method should take no arguments.
|
51
53
|
|
52
|
-
Here's an example of a
|
54
|
+
Here's an example of a job:
|
53
55
|
|
54
56
|
```ruby
|
55
57
|
# app/jobs/test_job.rb
|
@@ -72,6 +74,8 @@ class TestJob # This is not an Active Job job, but pretty legal Crono job.
|
|
72
74
|
end
|
73
75
|
```
|
74
76
|
|
77
|
+
_Please note that crono uses threads, so your code should be thread-safe_
|
78
|
+
|
75
79
|
#### Job Schedule
|
76
80
|
|
77
81
|
Schedule list is defined in the file `config/cronotab.rb`, that created using `crono:install`. The semantic is pretty straightforward:
|
data/lib/crono.rb
CHANGED
data/lib/crono/cli.rb
CHANGED
@@ -2,8 +2,6 @@ require 'crono'
|
|
2
2
|
require 'optparse'
|
3
3
|
|
4
4
|
module Crono
|
5
|
-
mattr_accessor :scheduler
|
6
|
-
|
7
5
|
# Crono::CLI - The main class for the crono daemon exacutable `bin/crono`
|
8
6
|
class CLI
|
9
7
|
include Singleton
|
@@ -33,7 +31,7 @@ module Crono
|
|
33
31
|
|
34
32
|
def setup_log
|
35
33
|
if config.daemonize
|
36
|
-
self.
|
34
|
+
self.logfile = config.logfile
|
37
35
|
daemonize
|
38
36
|
else
|
39
37
|
self.logfile = STDOUT
|
data/lib/crono/job.rb
CHANGED
@@ -61,7 +61,9 @@ module Crono
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def perform_job
|
64
|
-
performer.new
|
64
|
+
performer_instance = performer.new
|
65
|
+
performer_instance.instance_variable_set(:@_crono_job, self)
|
66
|
+
performer_instance.perform
|
65
67
|
finished_time_sec = format('%.2f', Time.now - last_performed_at)
|
66
68
|
rescue StandardError => e
|
67
69
|
handle_job_fail(e, finished_time_sec)
|
data/lib/crono/scheduler.rb
CHANGED
data/lib/crono/version.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
module Crono
|
2
|
+
def self.load_cronotab
|
3
|
+
cronotab_path = ENV['CRONOTAB'] || (defined?(Rails) &&
|
4
|
+
File.join(Rails.root, cronotab_path))
|
5
|
+
fail 'No cronotab defined' unless cronotab_path
|
6
|
+
puts "Load cronotab #{cronotab_path}"
|
7
|
+
require cronotab_path
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
namespace :crono do
|
12
|
+
desc 'Clean unused job stats from DB'
|
13
|
+
task clean: :environment do
|
14
|
+
Crono.scheduler = Crono::Scheduler.new
|
15
|
+
Crono.load_cronotab
|
16
|
+
current_job_ids = Crono.scheduler.jobs.map(&:job_id)
|
17
|
+
Crono::CronoJob.where.not(job_id: current_job_ids).destroy_all
|
18
|
+
end
|
19
|
+
|
20
|
+
desc 'Check cronotab.rb syntax'
|
21
|
+
task check: :environment do
|
22
|
+
Crono.scheduler = Crono::Scheduler.new
|
23
|
+
Crono.load_cronotab
|
24
|
+
puts 'Syntax ok'
|
25
|
+
end
|
26
|
+
end
|
data/spec/cli_spec.rb
CHANGED
data/spec/job_spec.rb
CHANGED
@@ -1,16 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
class TestJob
|
4
|
-
def perform
|
5
|
-
end
|
6
|
-
end
|
7
|
-
|
8
|
-
class TestFailingJob
|
9
|
-
def perform
|
10
|
-
fail 'Some error'
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
3
|
describe Crono::Job do
|
15
4
|
let(:period) { Crono::Period.new(2.day) }
|
16
5
|
let(:job) { Crono::Job.new(TestJob, period) }
|
@@ -37,15 +26,23 @@ describe Crono::Job do
|
|
37
26
|
expect(saved_log).to include 'Some error'
|
38
27
|
end
|
39
28
|
|
40
|
-
|
29
|
+
xit 'should set Job#healthy to true if perform ok' do
|
30
|
+
class TestJob
|
31
|
+
def perform
|
32
|
+
@_crono_job
|
33
|
+
end
|
34
|
+
end
|
41
35
|
job.perform.join
|
42
|
-
expect(job.healthy).to be true
|
43
36
|
end
|
44
37
|
|
45
38
|
it 'should set Job#healthy to false if perform with error' do
|
46
39
|
failing_job.perform.join
|
47
40
|
expect(failing_job.healthy).to be false
|
48
41
|
end
|
42
|
+
|
43
|
+
it 'should set @_crono_job variable to instance' do
|
44
|
+
job.perform
|
45
|
+
end
|
49
46
|
end
|
50
47
|
|
51
48
|
describe '#description' do
|
data/spec/scheduler_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
load 'tasks/crono_tasks.rake'
|
5
|
+
Rake::Task.define_task(:environment)
|
6
|
+
|
7
|
+
describe 'rake' do
|
8
|
+
describe 'crono:clean' do
|
9
|
+
it 'should clean unused tasks from DB' do
|
10
|
+
Crono::CronoJob.create!(job_id: 'used_job')
|
11
|
+
ENV['CRONOTAB'] = File.expand_path('../../assets/good_cronotab.rb', __FILE__)
|
12
|
+
Rake::Task['crono:clean'].invoke
|
13
|
+
expect(Crono::CronoJob.where(job_id: 'used_job')).not_to exist
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'crono:check' do
|
18
|
+
it 'should check cronotab syntax' do
|
19
|
+
ENV['CRONOTAB'] = File.expand_path('../../assets/bad_cronotab.rb', __FILE__)
|
20
|
+
expect { Rake::Task['crono:check'].invoke }.to raise_error
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/spec/web_spec.rb
CHANGED
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: 0.8.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dzmitry Plashchynski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activejob
|
@@ -209,12 +209,16 @@ files:
|
|
209
209
|
- lib/crono/orm/active_record/crono_job.rb
|
210
210
|
- lib/crono/performer_proxy.rb
|
211
211
|
- lib/crono/period.rb
|
212
|
+
- lib/crono/railtie.rb
|
212
213
|
- lib/crono/scheduler.rb
|
213
214
|
- lib/crono/version.rb
|
214
215
|
- lib/crono/web.rb
|
215
216
|
- lib/generators/crono/install/install_generator.rb
|
216
217
|
- lib/generators/crono/install/templates/cronotab.rb.erb
|
217
218
|
- lib/generators/crono/install/templates/migrations/create_crono_jobs.rb
|
219
|
+
- lib/tasks/crono_tasks.rake
|
220
|
+
- spec/assets/bad_cronotab.rb
|
221
|
+
- spec/assets/good_cronotab.rb
|
218
222
|
- spec/cli_spec.rb
|
219
223
|
- spec/config_spec.rb
|
220
224
|
- spec/job_spec.rb
|
@@ -223,6 +227,7 @@ files:
|
|
223
227
|
- spec/period_spec.rb
|
224
228
|
- spec/scheduler_spec.rb
|
225
229
|
- spec/spec_helper.rb
|
230
|
+
- spec/tasks/crono_tasks_spec.rb
|
226
231
|
- spec/web_spec.rb
|
227
232
|
- tmp/.gitkeep
|
228
233
|
- web/assets/custom.css
|