rjob 0.4.4 → 0.5.2
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/version.rb +1 -1
- data/lib/rjob/worker_process.rb +41 -35
- metadata +9 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3499587dfa6fa5db867d088dfc0f48757a204df0cd07a252c3f880ce827effe6
|
4
|
+
data.tar.gz: 6ff88dc58d9e39eb337980b4fe1241bd3afb493cd15aff370ab463e4b2d086b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77d9c95f465434e5efc942b5dca1a98c64bc2f15c2c12691b258f993569c68c29f1146958e8856633e9bee32bcc82119d687b3ee37a29eb6fa5163238eeacf08
|
7
|
+
data.tar.gz: 523ff1e067f99d9fb632c248d7b07157112d0d6197574e717d319900f76e8c646698f692388760dccb521abfbf36f88fe01b5c01614ec71f0b28fcf7319c5a71
|
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)
|
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
|
|
@@ -79,7 +83,10 @@ class Rjob::WorkerProcess
|
|
79
83
|
on.message do |_, bucket_no|
|
80
84
|
loop do
|
81
85
|
break unless @state == :running
|
82
|
-
|
86
|
+
|
87
|
+
@subscription_mutex.synchronize do
|
88
|
+
break unless start_processing_message_from_bucket(bucket_no)
|
89
|
+
end
|
83
90
|
end
|
84
91
|
end
|
85
92
|
end
|
@@ -91,45 +98,42 @@ class Rjob::WorkerProcess
|
|
91
98
|
exit 1
|
92
99
|
end
|
93
100
|
end
|
101
|
+
|
94
102
|
@subscription_thread.run
|
95
103
|
end
|
96
104
|
|
97
105
|
def run_iteration
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
scan_buckets
|
107
|
-
end
|
106
|
+
stop_threshold = (@max_queue_size * 0.7).to_i
|
107
|
+
if @thread_pool.queue_length >= stop_threshold || @state != :running
|
108
|
+
disable_subscription_thread
|
109
|
+
elsif @state == :running
|
110
|
+
if !@subscription_thread
|
111
|
+
enable_subscription_thread
|
112
|
+
sleep(ITERATION_TIMEOUT)
|
113
|
+
scan_buckets
|
108
114
|
end
|
115
|
+
end
|
109
116
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
end
|
117
|
+
if @state == :exiting
|
118
|
+
if @thread_pool.shutdown?
|
119
|
+
@state = :exited
|
120
|
+
elsif !@thread_pool.shuttingdown?
|
121
|
+
@thread_pool.shutdown
|
122
|
+
else
|
123
|
+
puts "Waiting shutdown..."
|
118
124
|
end
|
125
|
+
end
|
119
126
|
|
120
|
-
|
121
|
-
|
122
|
-
check_leadership
|
127
|
+
report_stats
|
123
128
|
|
124
|
-
|
125
|
-
exercise_leadership if @iteration_no % 2 == 0
|
126
|
-
end
|
129
|
+
check_leadership
|
127
130
|
|
128
|
-
|
129
|
-
|
130
|
-
rescue StandardError => e
|
131
|
-
raise e
|
131
|
+
if leader? && @state == :running
|
132
|
+
exercise_leadership if @iteration_no % 2 == 0
|
132
133
|
end
|
134
|
+
|
135
|
+
@iteration_no += 1
|
136
|
+
sleep(ITERATION_TIMEOUT) unless @state == :exited
|
133
137
|
end
|
134
138
|
|
135
139
|
def check_leadership
|
@@ -165,9 +169,9 @@ class Rjob::WorkerProcess
|
|
165
169
|
}
|
166
170
|
|
167
171
|
@context.redis do |r|
|
168
|
-
r.pipelined do
|
172
|
+
r.pipelined do |pl|
|
169
173
|
state_data.each do |k, v|
|
170
|
-
|
174
|
+
pl.hset(key_prefix, k, v.to_s)
|
171
175
|
end
|
172
176
|
end
|
173
177
|
end
|
@@ -186,6 +190,8 @@ class Rjob::WorkerProcess
|
|
186
190
|
|
187
191
|
return false if job_str == nil
|
188
192
|
|
193
|
+
job_str = job_str.b
|
194
|
+
|
189
195
|
# move to inside thread
|
190
196
|
job_processor = Rjob::JobProcessor.new(context, job_str)
|
191
197
|
|
@@ -202,7 +208,7 @@ class Rjob::WorkerProcess
|
|
202
208
|
remove_job_from_working(job_str, bucket)
|
203
209
|
end
|
204
210
|
end
|
205
|
-
rescue Concurrent::RejectedExecutionError
|
211
|
+
rescue Concurrent::RejectedExecutionError
|
206
212
|
@returned_count.increment
|
207
213
|
return_job_execution(job_str, bucket)
|
208
214
|
ensure
|
@@ -221,8 +227,8 @@ class Rjob::WorkerProcess
|
|
221
227
|
@context.script_runner.exec(r, :retry_job, [],
|
222
228
|
[
|
223
229
|
next_retry_at.to_s,
|
224
|
-
job.retry_num,
|
225
|
-
bucket,
|
230
|
+
job.retry_num.to_s,
|
231
|
+
bucket.to_s,
|
226
232
|
job.id.to_s,
|
227
233
|
job.payload,
|
228
234
|
@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.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- André D. Piske
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-04-08 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:
|
@@ -142,7 +128,8 @@ files:
|
|
142
128
|
- lib/rjob/worker.rb
|
143
129
|
- lib/rjob/worker_process.rb
|
144
130
|
homepage: https://gitlab.com/andrepiske/rjob
|
145
|
-
licenses:
|
131
|
+
licenses:
|
132
|
+
- Apache-2.0
|
146
133
|
metadata: {}
|
147
134
|
post_install_message:
|
148
135
|
rdoc_options: []
|
@@ -159,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
159
146
|
- !ruby/object:Gem::Version
|
160
147
|
version: '0'
|
161
148
|
requirements: []
|
162
|
-
rubygems_version: 3.
|
149
|
+
rubygems_version: 3.3.11
|
163
150
|
signing_key:
|
164
151
|
specification_version: 4
|
165
152
|
summary: Asynchronous job processing
|