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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 67a4a72affcc79b586581b3136af0ab5ec4ff859fcfc132511863c47c2fcef50
4
- data.tar.gz: 9afb72bca1e26e14d9ba9f1d1c6f4fd412e9a0c26c59dd8e5be0ac48f394f4b9
3
+ metadata.gz: 364e6b6c660f7b3fc31a24a1bd86942a7900aed84146ecf0a5fa3799653966b9
4
+ data.tar.gz: d450f1b80a5854b59d49c9bd9ca3f8df1c05b4dffe5d7e202efb95d15740e5e9
5
5
  SHA512:
6
- metadata.gz: 4914696405b65c9cd6515309788f062a8770007d9d8c847b0833f88a5bdacb61eeee455c6f20d9699124848023901eb8b35902a3f57452cd93e5c842aaa0fbcf
7
- data.tar.gz: 794b4f4e1c12e96d2f20e5e18eae379dace7ad9e58a9a7a47ad203a801c5ddc74e04afdf42814d5c518ccd67c8f55b8946cb94f2b7ec2fbf675ab1f2bfd13c91
6
+ metadata.gz: 2c2f0b54f42c2eaa8aac6b2b09dcb12adffce5763be7d89878971c9afc22460f73b4728f1bab42756fbf13bb4fe92d47a86f7ae41e759710faca153f958e861d
7
+ data.tar.gz: 06e74cef1bb61d06eaaa005dcf13be78465d016308025fde8af8a7035259645aadbbc2561fbf68db8745465500525495342ecd30db94915f4501dc2a09b4e0f2
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)
@@ -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
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Rjob
3
- VERSION = "0.5.0".freeze
3
+ VERSION = "0.5.3".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
 
@@ -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
- loop do
81
- break unless @state == :running
82
- break unless start_processing_message_from_bucket(bucket_no)
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
- 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
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
- 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
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
- report_stats
121
-
122
- check_leadership
125
+ report_stats
123
126
 
124
- if leader? && @state == :running
125
- exercise_leadership if @iteration_no % 2 == 0
126
- end
127
+ check_leadership
127
128
 
128
- @iteration_no += 1
129
- sleep(ITERATION_TIMEOUT) unless @state == :exited
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
- r.hset(key_prefix, k, v.to_s)
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 => e
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.0
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: 2021-09-30 00:00:00.000000000 Z
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: '4.1'
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: '4.1'
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.2.28
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: []