crono 0.8.7.pre → 0.8.8.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/crono.rb +1 -0
- data/lib/crono/cli.rb +1 -1
- data/lib/crono/cronotab.rb +10 -0
- data/lib/crono/job.rb +14 -9
- data/lib/crono/version.rb +1 -1
- data/lib/tasks/crono_tasks.rake +2 -12
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ada92b83365f8a5dc386a0206bc78c885406109
|
4
|
+
data.tar.gz: 4d8a3131f5fb9b8e80b2fd5ef289ff00e673b7fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f23b4482087ae0345cf642507e72afc0695fcfddd604eaadfb78bae95114dbe0ae902d39512e41cfaaeccf6f3c936e858eeac71b11bc45d728e64df92d49a6ef
|
7
|
+
data.tar.gz: d33fac75dba413e402171fb7a1fbdb94ee0ae78401cb4cf9ebf67d4f7027065a2dc66d0a3066e0a738338620f2764091b929a4958b4714bb8552090ea4c10bc9
|
data/Gemfile.lock
CHANGED
data/lib/crono.rb
CHANGED
data/lib/crono/cli.rb
CHANGED
@@ -21,6 +21,7 @@ module Crono
|
|
21
21
|
|
22
22
|
write_pid
|
23
23
|
load_rails
|
24
|
+
Cronotab.process(File.expand_path(config.cronotab))
|
24
25
|
print_banner
|
25
26
|
|
26
27
|
check_jobs
|
@@ -71,7 +72,6 @@ module Crono
|
|
71
72
|
require 'rails'
|
72
73
|
require File.expand_path('config/environment.rb')
|
73
74
|
::Rails.application.eager_load!
|
74
|
-
require File.expand_path(config.cronotab)
|
75
75
|
end
|
76
76
|
|
77
77
|
def check_jobs
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module Crono
|
2
|
+
class Cronotab
|
3
|
+
def self.process(cronotab_path = nil)
|
4
|
+
cronotab_path ||= ENV['CRONOTAB'] || (defined?(Rails) &&
|
5
|
+
File.join(Rails.root, Config::CRONOTAB))
|
6
|
+
fail 'No cronotab defined' unless cronotab_path
|
7
|
+
require cronotab_path
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
data/lib/crono/job.rb
CHANGED
@@ -6,18 +6,20 @@ module Crono
|
|
6
6
|
class Job
|
7
7
|
include Logging
|
8
8
|
|
9
|
-
attr_accessor :performer, :period, :last_performed_at,
|
10
|
-
:job_logger, :healthy
|
9
|
+
attr_accessor :performer, :period, :last_performed_at,
|
10
|
+
:next_performed_at, :job_log, :job_logger, :healthy
|
11
11
|
|
12
12
|
def initialize(performer, period)
|
13
13
|
self.performer, self.period = performer, period
|
14
14
|
self.job_log = StringIO.new
|
15
15
|
self.job_logger = Logger.new(job_log)
|
16
|
+
self.next_performed_at = period.next
|
16
17
|
@semaphore = Mutex.new
|
17
18
|
end
|
18
19
|
|
19
20
|
def next
|
20
|
-
|
21
|
+
return next_performed_at if next_performed_at.future?
|
22
|
+
Time.now
|
21
23
|
end
|
22
24
|
|
23
25
|
def description
|
@@ -31,6 +33,7 @@ module Crono
|
|
31
33
|
def perform
|
32
34
|
log "Perform #{performer}"
|
33
35
|
self.last_performed_at = Time.now
|
36
|
+
self.next_performed_at = period.next(since: last_performed_at)
|
34
37
|
|
35
38
|
Thread.new { perform_job }
|
36
39
|
end
|
@@ -44,6 +47,7 @@ module Crono
|
|
44
47
|
|
45
48
|
def load
|
46
49
|
self.last_performed_at = model.last_performed_at
|
50
|
+
self.next_performed_at = period.next(since: last_performed_at)
|
47
51
|
end
|
48
52
|
|
49
53
|
private
|
@@ -61,23 +65,24 @@ module Crono
|
|
61
65
|
|
62
66
|
def perform_job
|
63
67
|
performer.new.perform
|
64
|
-
finished_time_sec = format('%.2f', Time.now - last_performed_at)
|
65
68
|
rescue StandardError => e
|
66
|
-
handle_job_fail(e
|
69
|
+
handle_job_fail(e)
|
67
70
|
else
|
68
|
-
handle_job_success
|
71
|
+
handle_job_success
|
69
72
|
ensure
|
70
73
|
save
|
71
74
|
end
|
72
75
|
|
73
|
-
def handle_job_fail(exception
|
76
|
+
def handle_job_fail(exception)
|
77
|
+
finished_time_sec = format('%.2f', Time.now - last_performed_at)
|
74
78
|
self.healthy = false
|
75
79
|
log_error "Finished #{performer} in #{finished_time_sec} seconds"\
|
76
|
-
"with error: #{exception.message}"
|
80
|
+
" with error: #{exception.message}"
|
77
81
|
log_error exception.backtrace.join("\n")
|
78
82
|
end
|
79
83
|
|
80
|
-
def handle_job_success
|
84
|
+
def handle_job_success
|
85
|
+
finished_time_sec = format('%.2f', Time.now - last_performed_at)
|
81
86
|
self.healthy = true
|
82
87
|
log "Finished #{performer} in #{finished_time_sec} seconds"
|
83
88
|
end
|
data/lib/crono/version.rb
CHANGED
data/lib/tasks/crono_tasks.rake
CHANGED
@@ -1,18 +1,8 @@
|
|
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
1
|
namespace :crono do
|
12
2
|
desc 'Clean unused job stats from DB'
|
13
3
|
task clean: :environment do
|
14
4
|
Crono.scheduler = Crono::Scheduler.new
|
15
|
-
Crono.
|
5
|
+
Crono::Cronotab.process
|
16
6
|
current_job_ids = Crono.scheduler.jobs.map(&:job_id)
|
17
7
|
Crono::CronoJob.where.not(job_id: current_job_ids).destroy_all
|
18
8
|
end
|
@@ -20,7 +10,7 @@ namespace :crono do
|
|
20
10
|
desc 'Check cronotab.rb syntax'
|
21
11
|
task check: :environment do
|
22
12
|
Crono.scheduler = Crono::Scheduler.new
|
23
|
-
Crono.
|
13
|
+
Crono::Cronotab.process
|
24
14
|
puts 'Syntax ok'
|
25
15
|
end
|
26
16
|
end
|
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.8.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dzmitry Plashchynski
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activejob
|
@@ -206,6 +206,7 @@ files:
|
|
206
206
|
- lib/crono.rb
|
207
207
|
- lib/crono/cli.rb
|
208
208
|
- lib/crono/config.rb
|
209
|
+
- lib/crono/cronotab.rb
|
209
210
|
- lib/crono/job.rb
|
210
211
|
- lib/crono/logging.rb
|
211
212
|
- lib/crono/orm/active_record/crono_job.rb
|