rjob 0.5.0 → 0.5.1
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 +38 -32
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 241a7f0d98e6dc11f560e683e7454be5bc7c8864d39086fa1d7ff67974263051
|
4
|
+
data.tar.gz: cc6cd740afdc6fd9d61d7a427902edea296da4623d5cf7ec8f197ddfad522f0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 226a74975a3287b9cb0b50e63091edd909f84d033ddd5351c2e2d3f42f2be7acd127ee6ec57d49422147af294c991f3b6840a8f0844db0efa125bb1a7758dce5
|
7
|
+
data.tar.gz: d840b6e43f97320212b90d1220e2afe1a61f92a21b4617d87ef39484d88f4bd2c34e81367450ca4b7e5a3f1e1029be267aaba76c58e85f2b82094f5c1536c26c
|
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
|
@@ -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
|
|
@@ -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.5.
|
4
|
+
version: 0.5.1
|
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: 2021-
|
11
|
+
date: 2021-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oj
|