rocketjob 3.0.4 → 3.0.5
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61ffcbdf9443ca63dc699d732c9cc5c228b3505a
|
4
|
+
data.tar.gz: cbecb1f0d5df94328fa4190847aa8422211294a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e6de043e3a10b052855dfc5db392501bfad718242eecd1ef78110400e94d9fd571a88928877d613da0d520dbb984ed59cf61c66df18ce041fc85cd4028f135a
|
7
|
+
data.tar.gz: b1c2c436df6ceb73176a7cb65a343ab0a3c4b682099043270a8cc9409b79e272e029d2bc1b27b8e987629976030b929c3b3863bdf8a751e488c826d3ff5ec1c5
|
@@ -8,7 +8,7 @@ module RocketJob
|
|
8
8
|
# Example:
|
9
9
|
# class MyJob < RocketJob
|
10
10
|
# # Maximum number of workers to process instances of this job at the same time.
|
11
|
-
# self.
|
11
|
+
# self.throttle_running_jobs = 25
|
12
12
|
#
|
13
13
|
# def perform
|
14
14
|
# # ....
|
@@ -23,7 +23,7 @@ module RocketJob
|
|
23
23
|
# - If throughput is not as important as preventing brief spikes when many
|
24
24
|
# workers are running, add a double check into the perform:
|
25
25
|
# class MyJob < RocketJob
|
26
|
-
# self.
|
26
|
+
# self.throttle_running_jobs = 25
|
27
27
|
#
|
28
28
|
# def perform
|
29
29
|
# # (Optional) Prevent a brief spike from exceeding the wax worker throttle
|
@@ -36,8 +36,8 @@ module RocketJob
|
|
36
36
|
extend ActiveSupport::Concern
|
37
37
|
|
38
38
|
included do
|
39
|
-
class_attribute :
|
40
|
-
self.
|
39
|
+
class_attribute :throttle_running_jobs
|
40
|
+
self.throttle_running_jobs = nil
|
41
41
|
end
|
42
42
|
|
43
43
|
# Throttle to add when the throttle is exceeded
|
@@ -47,7 +47,7 @@ module RocketJob
|
|
47
47
|
|
48
48
|
# Returns [Boolean] whether the throttle for this job has been exceeded
|
49
49
|
def throttle_exceeded?
|
50
|
-
|
50
|
+
throttle_running_jobs && (throttle_running_jobs != 0) ? (self.class.running.where(:id.ne => id).count >= throttle_running_jobs) : false
|
51
51
|
end
|
52
52
|
|
53
53
|
# Prevent a brief spike from exceeding the wax worker throttle
|
@@ -57,8 +57,6 @@ module RocketJob
|
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
-
private
|
61
|
-
|
62
60
|
# Merge filter(s)
|
63
61
|
def throttle_merge_filter(target, source)
|
64
62
|
source.each_pair do |k, v|
|
@@ -69,6 +67,7 @@ module RocketJob
|
|
69
67
|
v
|
70
68
|
end
|
71
69
|
end
|
70
|
+
target
|
72
71
|
end
|
73
72
|
|
74
73
|
end
|
@@ -57,8 +57,9 @@ module RocketJob
|
|
57
57
|
job.rocket_job_fail_on_exception!(worker_name) { job.destroy }
|
58
58
|
logger.info "Destroyed expired job #{job.class.name}, id:#{job.id}"
|
59
59
|
when job.throttle_exceeded?
|
60
|
+
logger.debug { "Throttle exceeded with job #{job.class.name}, id:#{job.id}" }
|
60
61
|
# Add jobs filter to the current filter
|
61
|
-
throttle_merge_filter(filter, job.throttle_filter)
|
62
|
+
job.throttle_merge_filter(filter, job.throttle_filter)
|
62
63
|
# Restore retrieved job so that other workers can process it later
|
63
64
|
job.set(worker_name: nil, state: :queued)
|
64
65
|
else
|
data/lib/rocket_job/version.rb
CHANGED
@@ -7,16 +7,16 @@ module Plugins
|
|
7
7
|
|
8
8
|
class ThrottleJob < RocketJob::Job
|
9
9
|
# Only allow one to be processed at a time
|
10
|
-
self.
|
10
|
+
self.throttle_running_jobs = 1
|
11
11
|
|
12
12
|
def perform
|
13
13
|
21
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
describe RocketJob::Plugins::Job::
|
17
|
+
describe RocketJob::Plugins::Job::Throttle do
|
18
18
|
before do
|
19
|
-
|
19
|
+
RocketJob::Job.delete_all
|
20
20
|
end
|
21
21
|
|
22
22
|
describe '#throttle_exceeded?' do
|
@@ -50,6 +50,45 @@ module Plugins
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
+
describe '.rocket_job_next_job' do
|
54
|
+
before do
|
55
|
+
@worker_name = 'worker:123'
|
56
|
+
end
|
57
|
+
|
58
|
+
after do
|
59
|
+
@job.destroy if @job && !@job.new_record?
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'return nil when no jobs available' do
|
63
|
+
assert_nil RocketJob::Job.rocket_job_next_job(@worker_name)
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'return the job when others are queued, paused, failed, or complete' do
|
67
|
+
@job = ThrottleJob.create!
|
68
|
+
ThrottleJob.create!(state: :failed)
|
69
|
+
ThrottleJob.create!(state: :complete)
|
70
|
+
ThrottleJob.create!(state: :paused)
|
71
|
+
assert job = RocketJob::Job.rocket_job_next_job(@worker_name), -> { ThrottleJob.all.to_a.ai }
|
72
|
+
assert_equal @job.id, job.id, -> { ThrottleJob.all.to_a.ai }
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'return nil when other jobs are running' do
|
76
|
+
ThrottleJob.create!
|
77
|
+
@job = ThrottleJob.new
|
78
|
+
@job.start!
|
79
|
+
assert_nil RocketJob::Job.rocket_job_next_job(@worker_name), -> { ThrottleJob.all.to_a.ai }
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'add job to filter when other jobs are running' do
|
83
|
+
ThrottleJob.create!
|
84
|
+
@job = ThrottleJob.new
|
85
|
+
@job.start!
|
86
|
+
filter = {}
|
87
|
+
assert_nil RocketJob::Job.rocket_job_next_job(@worker_name, filter), -> { ThrottleJob.all.to_a.ai }
|
88
|
+
assert_equal 1, filter.size
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
53
92
|
end
|
54
93
|
end
|
55
94
|
end
|
@@ -43,30 +43,30 @@ module Plugins
|
|
43
43
|
|
44
44
|
describe '.rocket_job_next_job' do
|
45
45
|
before do
|
46
|
-
@job
|
47
|
-
@
|
46
|
+
@job = QuietJob.new
|
47
|
+
@worker_name = 'worker:123'
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'return nil when no jobs available' do
|
51
|
-
assert_nil RocketJob::Job.rocket_job_next_job(@
|
51
|
+
assert_nil RocketJob::Job.rocket_job_next_job(@worker_name)
|
52
52
|
end
|
53
53
|
|
54
54
|
it 'return the first job' do
|
55
55
|
@job.save!
|
56
|
-
assert job = RocketJob::Job.rocket_job_next_job(@
|
56
|
+
assert job = RocketJob::Job.rocket_job_next_job(@worker_name), 'Failed to find job'
|
57
57
|
assert_equal @job.id, job.id
|
58
58
|
end
|
59
59
|
|
60
60
|
it 'Ignore future dated jobs' do
|
61
61
|
@job.run_at = Time.now + 1.hour
|
62
62
|
@job.save!
|
63
|
-
assert_nil RocketJob::Job.rocket_job_next_job(@
|
63
|
+
assert_nil RocketJob::Job.rocket_job_next_job(@worker_name)
|
64
64
|
end
|
65
65
|
|
66
66
|
it 'Process future dated jobs when time is now' do
|
67
67
|
@job.run_at = Time.now
|
68
68
|
@job.save!
|
69
|
-
assert job = RocketJob::Job.rocket_job_next_job(@
|
69
|
+
assert job = RocketJob::Job.rocket_job_next_job(@worker_name), 'Failed to find future job'
|
70
70
|
assert_equal @job.id, job.id
|
71
71
|
end
|
72
72
|
|
@@ -74,7 +74,7 @@ module Plugins
|
|
74
74
|
count = RocketJob::Job.count
|
75
75
|
@job.expires_at = Time.now - 100
|
76
76
|
@job.save!
|
77
|
-
assert_nil RocketJob::Job.rocket_job_next_job(@
|
77
|
+
assert_nil RocketJob::Job.rocket_job_next_job(@worker_name)
|
78
78
|
assert_equal count, RocketJob::Job.count
|
79
79
|
end
|
80
80
|
end
|
@@ -173,8 +173,8 @@ module Plugins
|
|
173
173
|
|
174
174
|
describe '#rocket_job_active_workers' do
|
175
175
|
before do
|
176
|
-
@job
|
177
|
-
@
|
176
|
+
@job = QuietJob.create!
|
177
|
+
@worker_name = 'worker:123'
|
178
178
|
end
|
179
179
|
|
180
180
|
it 'should return empty hash for no active jobs' do
|
@@ -182,12 +182,12 @@ module Plugins
|
|
182
182
|
end
|
183
183
|
|
184
184
|
it 'should return active servers' do
|
185
|
-
assert job = RocketJob::Job.rocket_job_next_job(@
|
185
|
+
assert job = RocketJob::Job.rocket_job_next_job(@worker_name)
|
186
186
|
assert active = job.rocket_job_active_workers
|
187
187
|
assert_equal 1, active.size
|
188
188
|
assert active_worker = active.first
|
189
189
|
assert_equal @job.id, active_worker.job.id
|
190
|
-
assert_equal @
|
190
|
+
assert_equal @worker_name, active_worker.name
|
191
191
|
assert_equal job.started_at, active_worker.started_at
|
192
192
|
assert active_worker.duration_s
|
193
193
|
assert active_worker.duration
|
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.5
|
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-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|