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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 67a4a72affcc79b586581b3136af0ab5ec4ff859fcfc132511863c47c2fcef50
4
- data.tar.gz: 9afb72bca1e26e14d9ba9f1d1c6f4fd412e9a0c26c59dd8e5be0ac48f394f4b9
3
+ metadata.gz: 241a7f0d98e6dc11f560e683e7454be5bc7c8864d39086fa1d7ff67974263051
4
+ data.tar.gz: cc6cd740afdc6fd9d61d7a427902edea296da4623d5cf7ec8f197ddfad522f0c
5
5
  SHA512:
6
- metadata.gz: 4914696405b65c9cd6515309788f062a8770007d9d8c847b0833f88a5bdacb61eeee455c6f20d9699124848023901eb8b35902a3f57452cd93e5c842aaa0fbcf
7
- data.tar.gz: 794b4f4e1c12e96d2f20e5e18eae379dace7ad9e58a9a7a47ad203a801c5ddc74e04afdf42814d5c518ccd67c8f55b8946cb94f2b7ec2fbf675ab1f2bfd13c91
6
+ metadata.gz: 226a74975a3287b9cb0b50e63091edd909f84d033ddd5351c2e2d3f42f2be7acd127ee6ec57d49422147af294c991f3b6840a8f0844db0efa125bb1a7758dce5
7
+ data.tar.gz: d840b6e43f97320212b90d1220e2afe1a61f92a21b4617d87ef39484d88f4bd2c34e81367450ca4b7e5a3f1e1029be267aaba76c58e85f2b82094f5c1536c26c
data/lib/rjob/job.rb CHANGED
@@ -30,7 +30,7 @@ class Rjob::Job
30
30
  end
31
31
 
32
32
  def serialize
33
- "#{@id}!#{@retry_num}!#{@payload}".force_encoding(Encoding::ASCII_8BIT)
33
+ "#{@id}!#{@retry_num}!#{@payload}".b
34
34
  end
35
35
 
36
36
  def self.deserialize(context, job_str)
@@ -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
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Rjob
3
- VERSION = "0.5.0".freeze
3
+ VERSION = "0.5.1".freeze
4
4
  end
@@ -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
- @subscription_thread.raise(StopSubscription.new)
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
- break unless start_processing_message_from_bucket(bucket_no)
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
- begin
99
- stop_threshold = (@max_queue_size * 0.7).to_i
100
- if @thread_pool.queue_length >= stop_threshold || @state != :running
101
- disable_subscription_thread
102
- elsif @state == :running
103
- if !@subscription_thread
104
- enable_subscription_thread
105
- sleep(ITERATION_TIMEOUT)
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
- if @state == :exiting
111
- if @thread_pool.shutdown?
112
- @state = :exited
113
- elsif !@thread_pool.shuttingdown?
114
- @thread_pool.shutdown
115
- else
116
- puts "Waiting shutdown..."
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
- report_stats
121
-
122
- check_leadership
127
+ report_stats
123
128
 
124
- if leader? && @state == :running
125
- exercise_leadership if @iteration_no % 2 == 0
126
- end
129
+ check_leadership
127
130
 
128
- @iteration_no += 1
129
- sleep(ITERATION_TIMEOUT) unless @state == :exited
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.0
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-09-30 00:00:00.000000000 Z
11
+ date: 2021-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj