rjob 0.5.0 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rjob/job.rb +1 -1
- data/lib/rjob/recurring_job.rb +1 -1
- data/lib/rjob/scripts/enqueue_job.rb +1 -1
- data/lib/rjob/scripts/scan_buckets.rb +1 -1
- data/lib/rjob/version.rb +1 -1
- data/lib/rjob/worker_process.rb +41 -37
- metadata +10 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 364e6b6c660f7b3fc31a24a1bd86942a7900aed84146ecf0a5fa3799653966b9
|
4
|
+
data.tar.gz: d450f1b80a5854b59d49c9bd9ca3f8df1c05b4dffe5d7e202efb95d15740e5e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c2f0b54f42c2eaa8aac6b2b09dcb12adffce5763be7d89878971c9afc22460f73b4728f1bab42756fbf13bb4fe92d47a86f7ae41e759710faca153f958e861d
|
7
|
+
data.tar.gz: 06e74cef1bb61d06eaaa005dcf13be78465d016308025fde8af8a7035259645aadbbc2561fbf68db8745465500525495342ecd30db94915f4501dc2a09b4e0f2
|
data/lib/rjob/job.rb
CHANGED
data/lib/rjob/recurring_job.rb
CHANGED
@@ -20,7 +20,7 @@ class Rjob::RecurringJob
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def maybe_enqueue(redis)
|
23
|
-
key_name = "#{@context.prefix}:recurring:1:#{@unique_id}:lastrun"
|
23
|
+
key_name = "#{@context.prefix}:recurring:1:#{@unique_id}:lastrun".b
|
24
24
|
current_time = Time.now
|
25
25
|
|
26
26
|
last_run_str = redis.get(key_name)
|
@@ -14,7 +14,7 @@ class Rjob::Scripts::EnqueueJob < Rjob::Scripts::RedisScript
|
|
14
14
|
local job_id = r.call('incr', prefix .. ':next')
|
15
15
|
local bucket = job_id % bucket_count
|
16
16
|
r.call('lpush', prefix .. ':jobs:' .. bucket, job_id .. '!0!' .. job_data)
|
17
|
-
r.call('publish', prefix .. ':jobs', bucket)
|
17
|
+
r.call('publish', prefix .. ':jobs', tostring(bucket))
|
18
18
|
return job_id
|
19
19
|
LUA
|
20
20
|
end
|
@@ -14,7 +14,7 @@ class Rjob::Scripts::ScanBuckets < Rjob::Scripts::RedisScript
|
|
14
14
|
for i=0,bucket_count-1 do
|
15
15
|
local len = r.call('llen', prefix .. ':jobs:' .. i)
|
16
16
|
if len > 0 then
|
17
|
-
r.call('publish', prefix .. ':jobs', i)
|
17
|
+
r.call('publish', prefix .. ':jobs', tostring(i))
|
18
18
|
end
|
19
19
|
end
|
20
20
|
return 1
|
data/lib/rjob/version.rb
CHANGED
data/lib/rjob/worker_process.rb
CHANGED
@@ -24,6 +24,7 @@ class Rjob::WorkerProcess
|
|
24
24
|
@max_queue_size = 20
|
25
25
|
max_threads = @context.config.fetch(:max_threads, 2)
|
26
26
|
|
27
|
+
@subscription_mutex = Mutex.new
|
27
28
|
@subscription_thread = nil
|
28
29
|
@thread_pool = Concurrent::ThreadPoolExecutor.new(
|
29
30
|
min_threads: [2, max_threads].min,
|
@@ -66,7 +67,10 @@ class Rjob::WorkerProcess
|
|
66
67
|
|
67
68
|
def disable_subscription_thread
|
68
69
|
return unless @subscription_thread
|
69
|
-
@
|
70
|
+
@subscription_mutex.synchronize do
|
71
|
+
@subscription_thread.raise(StopSubscription.new)
|
72
|
+
end
|
73
|
+
|
70
74
|
@subscription_thread = nil
|
71
75
|
end
|
72
76
|
|
@@ -77,9 +81,10 @@ class Rjob::WorkerProcess
|
|
77
81
|
begin
|
78
82
|
@pubsub_redis.subscribe("#{@prefix}:jobs") do |on|
|
79
83
|
on.message do |_, bucket_no|
|
80
|
-
|
81
|
-
|
82
|
-
|
84
|
+
@pubsub_redis.unsubscribe unless @state == :running
|
85
|
+
|
86
|
+
@subscription_mutex.synchronize do
|
87
|
+
start_processing_message_from_bucket(bucket_no)
|
83
88
|
end
|
84
89
|
end
|
85
90
|
end
|
@@ -91,45 +96,42 @@ class Rjob::WorkerProcess
|
|
91
96
|
exit 1
|
92
97
|
end
|
93
98
|
end
|
99
|
+
|
94
100
|
@subscription_thread.run
|
95
101
|
end
|
96
102
|
|
97
103
|
def run_iteration
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
scan_buckets
|
107
|
-
end
|
104
|
+
stop_threshold = (@max_queue_size * 0.7).to_i
|
105
|
+
if @thread_pool.queue_length >= stop_threshold || @state != :running
|
106
|
+
disable_subscription_thread
|
107
|
+
elsif @state == :running
|
108
|
+
if !@subscription_thread
|
109
|
+
enable_subscription_thread
|
110
|
+
sleep(ITERATION_TIMEOUT)
|
111
|
+
scan_buckets
|
108
112
|
end
|
113
|
+
end
|
109
114
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
end
|
115
|
+
if @state == :exiting
|
116
|
+
if @thread_pool.shutdown?
|
117
|
+
@state = :exited
|
118
|
+
elsif !@thread_pool.shuttingdown?
|
119
|
+
@thread_pool.shutdown
|
120
|
+
else
|
121
|
+
puts "Waiting shutdown..."
|
118
122
|
end
|
123
|
+
end
|
119
124
|
|
120
|
-
|
121
|
-
|
122
|
-
check_leadership
|
125
|
+
report_stats
|
123
126
|
|
124
|
-
|
125
|
-
exercise_leadership if @iteration_no % 2 == 0
|
126
|
-
end
|
127
|
+
check_leadership
|
127
128
|
|
128
|
-
|
129
|
-
|
130
|
-
rescue StandardError => e
|
131
|
-
raise e
|
129
|
+
if leader? && @state == :running
|
130
|
+
exercise_leadership if @iteration_no % 2 == 0
|
132
131
|
end
|
132
|
+
|
133
|
+
@iteration_no += 1
|
134
|
+
sleep(ITERATION_TIMEOUT) unless @state == :exited
|
133
135
|
end
|
134
136
|
|
135
137
|
def check_leadership
|
@@ -165,9 +167,9 @@ class Rjob::WorkerProcess
|
|
165
167
|
}
|
166
168
|
|
167
169
|
@context.redis do |r|
|
168
|
-
r.pipelined do
|
170
|
+
r.pipelined do |pl|
|
169
171
|
state_data.each do |k, v|
|
170
|
-
|
172
|
+
pl.hset(key_prefix, k, v.to_s)
|
171
173
|
end
|
172
174
|
end
|
173
175
|
end
|
@@ -186,6 +188,8 @@ class Rjob::WorkerProcess
|
|
186
188
|
|
187
189
|
return false if job_str == nil
|
188
190
|
|
191
|
+
job_str = job_str.b
|
192
|
+
|
189
193
|
# move to inside thread
|
190
194
|
job_processor = Rjob::JobProcessor.new(context, job_str)
|
191
195
|
|
@@ -202,7 +206,7 @@ class Rjob::WorkerProcess
|
|
202
206
|
remove_job_from_working(job_str, bucket)
|
203
207
|
end
|
204
208
|
end
|
205
|
-
rescue Concurrent::RejectedExecutionError
|
209
|
+
rescue Concurrent::RejectedExecutionError
|
206
210
|
@returned_count.increment
|
207
211
|
return_job_execution(job_str, bucket)
|
208
212
|
ensure
|
@@ -221,8 +225,8 @@ class Rjob::WorkerProcess
|
|
221
225
|
@context.script_runner.exec(r, :retry_job, [],
|
222
226
|
[
|
223
227
|
next_retry_at.to_s,
|
224
|
-
job.retry_num,
|
225
|
-
bucket,
|
228
|
+
job.retry_num.to_s,
|
229
|
+
bucket.to_s,
|
226
230
|
job.id.to_s,
|
227
231
|
job.payload,
|
228
232
|
@prefix
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rjob
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- André D. Piske
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oj
|
@@ -42,16 +42,16 @@ dependencies:
|
|
42
42
|
name: redis
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 3.0.5
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 3.0.5
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: msgpack
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,20 +100,6 @@ dependencies:
|
|
100
100
|
- - "~>"
|
101
101
|
- !ruby/object:Gem::Version
|
102
102
|
version: 1.1.6
|
103
|
-
- !ruby/object:Gem::Dependency
|
104
|
-
name: rake
|
105
|
-
requirement: !ruby/object:Gem::Requirement
|
106
|
-
requirements:
|
107
|
-
- - "~>"
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
version: '13.0'
|
110
|
-
type: :runtime
|
111
|
-
prerelease: false
|
112
|
-
version_requirements: !ruby/object:Gem::Requirement
|
113
|
-
requirements:
|
114
|
-
- - "~>"
|
115
|
-
- !ruby/object:Gem::Version
|
116
|
-
version: '13.0'
|
117
103
|
description: 'RJob: asynchronous job processing'
|
118
104
|
email: andrepiske@gmail.com
|
119
105
|
executables:
|
@@ -145,7 +131,7 @@ homepage: https://gitlab.com/andrepiske/rjob
|
|
145
131
|
licenses:
|
146
132
|
- Apache-2.0
|
147
133
|
metadata: {}
|
148
|
-
post_install_message:
|
134
|
+
post_install_message:
|
149
135
|
rdoc_options: []
|
150
136
|
require_paths:
|
151
137
|
- lib
|
@@ -160,8 +146,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
160
146
|
- !ruby/object:Gem::Version
|
161
147
|
version: '0'
|
162
148
|
requirements: []
|
163
|
-
rubygems_version: 3.
|
164
|
-
signing_key:
|
149
|
+
rubygems_version: 3.3.11
|
150
|
+
signing_key:
|
165
151
|
specification_version: 4
|
166
152
|
summary: Asynchronous job processing
|
167
153
|
test_files: []
|