rocketjob 3.0.3 → 3.0.4
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/Rakefile +11 -1
- data/lib/rocket_job/dirmon_entry.rb +2 -2
- data/lib/rocket_job/plugins/job/model.rb +6 -0
- data/lib/rocket_job/plugins/job/state_machine.rb +2 -2
- data/lib/rocket_job/plugins/job/worker.rb +1 -1
- data/lib/rocket_job/plugins/rufus/cron_line.rb +1 -2
- data/lib/rocket_job/plugins/rufus/zo_time.rb +57 -8
- data/lib/rocket_job/server.rb +1 -1
- data/lib/rocket_job/version.rb +1 -1
- data/lib/rocket_job/worker.rb +16 -9
- data/test/plugins/state_machine_test.rb +8 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6cc91f7e665fcbe24f0ff2fd388540e5dc04274
|
4
|
+
data.tar.gz: 2c7277a7216c799d0ad59c645a5d3100079bf8f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69f216ca8f7b62df4fd72bae9f8ef5d4bfbdcff166df82ae494ca8986cd9cc0360e5fb1886334697a5144c3c70b34ce054e36ac0ccde66aa009aab6e71a5a727
|
7
|
+
data.tar.gz: c600c821b1c881c428930f4f9e9133413205ce87811cd001d3b0ceba8c27455bc131d3d7695582f3e1a802872646f1a34c985297847f55a9ecb2495d93a1bec4
|
data/Rakefile
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
# Setup bundler to avoid having to run bundle exec all the time.
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler/setup'
|
4
|
+
|
1
5
|
require 'rake/testtask'
|
2
6
|
require_relative 'lib/rocket_job/version'
|
3
7
|
|
@@ -18,4 +22,10 @@ Rake::TestTask.new(:test) do |t|
|
|
18
22
|
t.warning = false
|
19
23
|
end
|
20
24
|
|
21
|
-
|
25
|
+
# By default run tests against all appraisals
|
26
|
+
if !ENV["APPRAISAL_INITIALIZED"] && !ENV["TRAVIS"]
|
27
|
+
require 'appraisal'
|
28
|
+
task default: :appraisal
|
29
|
+
else
|
30
|
+
task default: :test
|
31
|
+
end
|
@@ -78,7 +78,7 @@ module RocketJob
|
|
78
78
|
# -> :failed -> :active
|
79
79
|
# -> :disabled
|
80
80
|
# -> :disabled -> :active
|
81
|
-
aasm column: :state do
|
81
|
+
aasm column: :state, whiny_persistence: true do
|
82
82
|
# DirmonEntry is `pending` until it is approved
|
83
83
|
state :pending, initial: true
|
84
84
|
|
@@ -236,7 +236,7 @@ module RocketJob
|
|
236
236
|
next if file_name.include?(self.class.default_archive_directory)
|
237
237
|
|
238
238
|
# Security check?
|
239
|
-
if (whitelist_paths.size > 0) && whitelist_paths.none? { |whitepath| file_name.start_with?(whitepath) }
|
239
|
+
if (whitelist_paths.size > 0) && whitelist_paths.none? { |whitepath| file_name.to_s.start_with?(whitepath) }
|
240
240
|
logger.error "Skipping file: #{file_name} since it is not in any of the whitelisted paths: #{whitelist_paths.join(', ')}"
|
241
241
|
next
|
242
242
|
end
|
@@ -253,6 +253,12 @@ module RocketJob
|
|
253
253
|
h
|
254
254
|
end
|
255
255
|
|
256
|
+
# Returns [Boolean] whether the worker runs on a particular server.
|
257
|
+
def worker_on_server?(server_name)
|
258
|
+
return false unless worker_name.present? && server_name.present?
|
259
|
+
worker_name.start_with?(server_name)
|
260
|
+
end
|
261
|
+
|
256
262
|
end
|
257
263
|
end
|
258
264
|
end
|
@@ -19,7 +19,7 @@ module RocketJob
|
|
19
19
|
# -> :aborted
|
20
20
|
# -> :queued (when a worker dies)
|
21
21
|
# -> :aborted
|
22
|
-
aasm column: :state do
|
22
|
+
aasm column: :state, whiny_persistence: true do
|
23
23
|
# Job has been created and is queued for processing ( Initial state )
|
24
24
|
state :queued, initial: true
|
25
25
|
|
@@ -76,7 +76,7 @@ module RocketJob
|
|
76
76
|
|
77
77
|
event :requeue do
|
78
78
|
transitions from: :running, to: :queued,
|
79
|
-
if: -> server_name {
|
79
|
+
if: -> server_name { worker_on_server?(server_name) },
|
80
80
|
after: :rocket_job_clear_started_at
|
81
81
|
end
|
82
82
|
end
|
@@ -169,7 +169,7 @@ module RocketJob
|
|
169
169
|
|
170
170
|
# Returns [Hash<String:[Array<ActiveWorker>]>] All servers actively working on this job
|
171
171
|
def rocket_job_active_workers(server_name = nil)
|
172
|
-
return [] if !running? || (server_name && !
|
172
|
+
return [] if !running? || (server_name && !worker_on_server?(server_name))
|
173
173
|
[ActiveWorker.new(worker_name, started_at, self)]
|
174
174
|
end
|
175
175
|
|
@@ -85,7 +85,7 @@ module RocketJob::Plugins::Rufus
|
|
85
85
|
|
86
86
|
fail ArgumentError.new(
|
87
87
|
"invalid cronline: '#{line}'"
|
88
|
-
) if es && es.find { |e| ! e.is_a?(
|
88
|
+
) if es && es.find { |e| ! e.is_a?(Integer) }
|
89
89
|
end
|
90
90
|
|
91
91
|
if @days && @days.include?(0) # gh-221
|
@@ -517,4 +517,3 @@ module RocketJob::Plugins::Rufus
|
|
517
517
|
end
|
518
518
|
end
|
519
519
|
end
|
520
|
-
|
@@ -39,7 +39,10 @@ module RocketJob::Plugins::Rufus
|
|
39
39
|
fail ArgumentError.new(
|
40
40
|
"cannot determine timezone from #{zone.inspect}" +
|
41
41
|
" (etz:#{ENV['TZ'].inspect},tnz:#{Time.now.zone.inspect}," +
|
42
|
-
"tzid:#{defined?(TZInfo::Data).inspect})"
|
42
|
+
"tzid:#{defined?(TZInfo::Data).inspect})\n" +
|
43
|
+
"Try setting `ENV['TZ'] = 'Continent/City'` in your script " +
|
44
|
+
"(see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)" +
|
45
|
+
(defined?(TZInfo::Data) ? '' : " and adding 'tzinfo-data' to your gems")
|
43
46
|
) unless @zone
|
44
47
|
|
45
48
|
@time = nil # cache for #to_time result
|
@@ -277,6 +280,7 @@ module RocketJob::Plugins::Rufus
|
|
277
280
|
end
|
278
281
|
|
279
282
|
def self.get_tzone(str)
|
283
|
+
|
280
284
|
return str if str.is_a?(::TZInfo::Timezone)
|
281
285
|
|
282
286
|
# discard quickly when it's certainly not a timezone
|
@@ -284,10 +288,19 @@ module RocketJob::Plugins::Rufus
|
|
284
288
|
return nil if str == nil
|
285
289
|
return nil if str == '*'
|
286
290
|
|
291
|
+
ostr = str
|
292
|
+
str = :current if str == :local
|
293
|
+
|
294
|
+
# use Rails' zone by default if Rails is present
|
295
|
+
|
296
|
+
return Time.zone.tzinfo if (
|
297
|
+
ENV['TZ'].nil? && str == :current &&
|
298
|
+
Time.respond_to?(:zone) && Time.zone.respond_to?(:tzinfo)
|
299
|
+
)
|
300
|
+
|
287
301
|
# ok, it's a timezone then
|
288
302
|
|
289
|
-
|
290
|
-
str = ENV['TZ'] || Time.now.zone if str == :current || str == :local
|
303
|
+
str = ENV['TZ'] || Time.now.zone if str == :current
|
291
304
|
|
292
305
|
# utc_offset
|
293
306
|
|
@@ -298,7 +311,7 @@ module RocketJob::Plugins::Rufus
|
|
298
311
|
str = (sc > 0 ? "%s%02d:%02d:%02d" : "%s%02d:%02d") % [ sn, hr, mn, sc ]
|
299
312
|
end
|
300
313
|
|
301
|
-
return nil if str.
|
314
|
+
return nil if str.index('#')
|
302
315
|
# counters "sun#2", etc... On OSX would go all the way to true
|
303
316
|
|
304
317
|
# vanilla time zones
|
@@ -363,11 +376,14 @@ module RocketJob::Plugins::Rufus
|
|
363
376
|
) if hr
|
364
377
|
end
|
365
378
|
|
366
|
-
#
|
379
|
+
# try with ENV['TZ']
|
367
380
|
|
368
|
-
z =
|
369
|
-
|
370
|
-
|
381
|
+
z = ostr == :current && (::TZInfo::Timezone.get(ENV['TZ']) rescue nil)
|
382
|
+
return z if z
|
383
|
+
|
384
|
+
# ask the system
|
385
|
+
|
386
|
+
z = ostr == :current && (debian_tz || centos_tz || osx_tz)
|
371
387
|
return z if z
|
372
388
|
|
373
389
|
# so it's not a timezone.
|
@@ -375,6 +391,39 @@ module RocketJob::Plugins::Rufus
|
|
375
391
|
nil
|
376
392
|
end
|
377
393
|
|
394
|
+
def self.debian_tz
|
395
|
+
|
396
|
+
path = '/etc/timezone'
|
397
|
+
|
398
|
+
File.exist?(path) &&
|
399
|
+
(::TZInfo::Timezone.get(File.read(path).strip) rescue nil)
|
400
|
+
end
|
401
|
+
|
402
|
+
def self.centos_tz
|
403
|
+
|
404
|
+
path = '/etc/sysconfig/clock'
|
405
|
+
|
406
|
+
File.open(path, 'rb') do |f|
|
407
|
+
until f.eof?
|
408
|
+
m = f.readline.match(/ZONE="([^"]+)"/)
|
409
|
+
return (::TZInfo::Timezone.get(m[1]) rescue nil) if m
|
410
|
+
end
|
411
|
+
end if File.exist?(path)
|
412
|
+
|
413
|
+
nil
|
414
|
+
end
|
415
|
+
|
416
|
+
def self.osx_tz
|
417
|
+
|
418
|
+
path = '/etc/localtime'
|
419
|
+
|
420
|
+
return nil unless File.exist?(path)
|
421
|
+
|
422
|
+
::TZInfo::Timezone.get(
|
423
|
+
File.readlink(path).split('/')[4..-1].join('/')
|
424
|
+
) rescue nil
|
425
|
+
end
|
426
|
+
|
378
427
|
def self.local_tzone
|
379
428
|
|
380
429
|
get_tzone(:local)
|
data/lib/rocket_job/server.rb
CHANGED
data/lib/rocket_job/version.rb
CHANGED
data/lib/rocket_job/worker.rb
CHANGED
@@ -40,7 +40,7 @@ module RocketJob
|
|
40
40
|
@shutdown = false
|
41
41
|
end
|
42
42
|
@name = "#{server_name}:#{id}"
|
43
|
-
@re_check_seconds = re_check_seconds || 60
|
43
|
+
@re_check_seconds = (re_check_seconds || 60).to_f
|
44
44
|
@re_check_start = Time.now
|
45
45
|
@filter = filter || {}
|
46
46
|
@current_filter = @filter.dup
|
@@ -96,15 +96,12 @@ module RocketJob
|
|
96
96
|
# Process the next available job
|
97
97
|
# Returns [Boolean] whether any job was actually processed
|
98
98
|
def process_available_jobs
|
99
|
-
# Only clear out the current_filter after every `re_check_seconds`
|
100
|
-
time = Time.now
|
101
|
-
if (time - @re_check_start) > re_check_seconds.to_f
|
102
|
-
@re_check_start = time
|
103
|
-
self.current_filter = filter.dup
|
104
|
-
end
|
105
|
-
|
106
99
|
processed = false
|
107
|
-
while
|
100
|
+
while !shutdown?
|
101
|
+
reset_filter_if_expired
|
102
|
+
job = Job.rocket_job_next_job(name, current_filter)
|
103
|
+
break unless job
|
104
|
+
|
108
105
|
logger.fast_tag("job:#{job.id}") do
|
109
106
|
unless job.rocket_job_work(self, false, current_filter)
|
110
107
|
processed = true
|
@@ -114,6 +111,16 @@ module RocketJob
|
|
114
111
|
processed
|
115
112
|
end
|
116
113
|
|
114
|
+
# Resets the current job filter if the relevant time interval has passed
|
115
|
+
def reset_filter_if_expired
|
116
|
+
# Only clear out the current_filter after every `re_check_seconds`
|
117
|
+
time = Time.now
|
118
|
+
if (time - @re_check_start) > re_check_seconds
|
119
|
+
@re_check_start = time
|
120
|
+
self.current_filter = filter.dup
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
117
124
|
end
|
118
125
|
end
|
119
126
|
|
@@ -12,7 +12,7 @@ module Plugins
|
|
12
12
|
field :state, type: String
|
13
13
|
validates_presence_of :name, :state
|
14
14
|
|
15
|
-
aasm column: :state do
|
15
|
+
aasm column: :state, whiny_persistence: true do
|
16
16
|
state :pending, initial: true
|
17
17
|
state :enabled
|
18
18
|
|
@@ -31,19 +31,23 @@ module Plugins
|
|
31
31
|
@doc.destroy if @doc && !@doc.new_record?
|
32
32
|
end
|
33
33
|
|
34
|
-
describe '#
|
34
|
+
describe '#create!' do
|
35
35
|
it 'raises an exception when a validation fails on create!' do
|
36
36
|
assert_raises Mongoid::Errors::Validations do
|
37
37
|
@doc = Test.create!
|
38
38
|
end
|
39
39
|
end
|
40
|
+
end
|
40
41
|
|
42
|
+
describe '#save!' do
|
41
43
|
it 'raises an exception when a validation fails on save' do
|
42
44
|
assert_raises Mongoid::Errors::Validations do
|
43
45
|
@doc.save!
|
44
46
|
end
|
45
47
|
end
|
48
|
+
end
|
46
49
|
|
50
|
+
describe '#transition!' do
|
47
51
|
it 'raises an exception when a validation fails on state transition with save' do
|
48
52
|
assert_raises Mongoid::Errors::Validations do
|
49
53
|
@doc.enable!
|
@@ -51,12 +55,13 @@ module Plugins
|
|
51
55
|
assert @doc.pending?
|
52
56
|
refute @doc.valid?
|
53
57
|
end
|
58
|
+
end
|
54
59
|
|
60
|
+
describe '#transition' do
|
55
61
|
it 'does not raise an exception when a validation fails on state transition without save' do
|
56
62
|
@doc.enable
|
57
63
|
assert @doc.enabled?
|
58
64
|
end
|
59
|
-
|
60
65
|
end
|
61
66
|
|
62
67
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rocketjob
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Reid Morrison
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|