backburner-allq 1.0.19 → 1.0.24
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/deploy.sh +1 -1
- data/lib/backburner.rb +3 -0
- data/lib/backburner/allq_wrapper.rb +3 -2
- data/lib/backburner/configuration.rb +1 -1
- data/lib/backburner/job.rb +3 -2
- data/lib/backburner/version.rb +1 -1
- data/lib/backburner/worker.rb +10 -7
- data/lib/backburner/workers/threading.rb +1 -1
- data/lib/backburner/workers/threads_on_fork.rb +2 -6
- 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: ca025bad38a673fdca1c9649c0eb697f0a25f38e9b9181c609c242e2cbc694e9
|
4
|
+
data.tar.gz: e1a608abe130c76a3d105c5b28d221263c31c264e425306d2fb86b91c63f2b90
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e36f0d3d7c633705f9c51632b34927d1ce790888544690e1c862a1d30f3e8a783209863771a95b6c4fb20556890a1083691d6a5cde317d330248ad1c88f2bc0
|
7
|
+
data.tar.gz: a92844eb1114d9afec02017ce932cfc0ab7510125250a9e38908106369ed1b6613ca72a4cf2a5ce97cf4aaf3f7963a4c468aa7a0a7323dd26e3679678100d8d4
|
data/Gemfile
CHANGED
data/deploy.sh
CHANGED
data/lib/backburner.rb
CHANGED
@@ -29,6 +29,9 @@ module Backburner
|
|
29
29
|
Backburner::Worker.enqueue(job_class, args, {})
|
30
30
|
end
|
31
31
|
|
32
|
+
def enqueue(job_class, args, shard_key = nil)
|
33
|
+
enqueue(job_class, args, { shard_key: shard_key.nil? ? "X" : shard_key.to_s })
|
34
|
+
end
|
32
35
|
# Begins working on jobs enqueued with optional tubes specified
|
33
36
|
#
|
34
37
|
# @example
|
@@ -81,6 +81,7 @@ module Backburner
|
|
81
81
|
end
|
82
82
|
|
83
83
|
class AllQWrapper
|
84
|
+
DEFAULT_TIMEOUT = 17800
|
84
85
|
def initialize(url = 'localhost:8090')
|
85
86
|
allq_conf = Allq::Configuration.new do |config|
|
86
87
|
config.host = url
|
@@ -182,7 +183,7 @@ module Backburner
|
|
182
183
|
def build_new_job(body, options)
|
183
184
|
adjusted_priority = map_priority(options[:pri] || 5)
|
184
185
|
|
185
|
-
ttl = options[:ttl] ||
|
186
|
+
ttl = options[:ttl] || options[:ttr] || DEFAULT_TIMEOUT
|
186
187
|
tube_name = options[:tube_name] || 'default'
|
187
188
|
delay = options[:delay] || 0
|
188
189
|
parent_id = options[:parent_id]
|
@@ -199,7 +200,7 @@ module Backburner
|
|
199
200
|
|
200
201
|
def build_new_parent_job(body, options)
|
201
202
|
adjusted_priority = map_priority(options[:pri] || 5)
|
202
|
-
ttl = options[:ttl] ||
|
203
|
+
ttl = options[:ttl] || options[:ttr] || DEFAULT_TIMEOUT
|
203
204
|
tube_name = options[:tube_name] || 'default'
|
204
205
|
delay = options[:delay] || 0
|
205
206
|
parent_id = options[:parent_id]
|
data/lib/backburner/job.rb
CHANGED
@@ -25,6 +25,7 @@ module Backburner
|
|
25
25
|
@body = task.body.is_a?(Hash) ? task.body : Backburner.configuration.job_parser_proc.call(task.body)
|
26
26
|
@name = body["class"] || body[:class]
|
27
27
|
@args = body["args"] || body[:args]
|
28
|
+
@ttr = body["ttr"] || body[:ttr]
|
28
29
|
rescue => ex # Job was not valid format
|
29
30
|
# self.bury
|
30
31
|
# raise JobFormatInvalid, "Job body could not be parsed: #{ex.inspect}"
|
@@ -42,13 +43,13 @@ module Backburner
|
|
42
43
|
# @example
|
43
44
|
# @task.process
|
44
45
|
#
|
45
|
-
def process
|
46
|
+
def process
|
46
47
|
# Invoke before hook and stop if false
|
47
48
|
res = @hooks.invoke_hook_events(job_name, :before_perform, *args)
|
48
49
|
return false unless res
|
49
50
|
# Execute the job
|
50
51
|
@hooks.around_hook_events(job_name, :around_perform, *args) do
|
51
|
-
job_class.perform(*args)
|
52
|
+
timeout_job_after(@ttr > 1 ? @ttr - 1 : @ttr) { job_class.perform(*args) }
|
52
53
|
end
|
53
54
|
task.delete
|
54
55
|
# Invoke after perform hook
|
data/lib/backburner/version.rb
CHANGED
data/lib/backburner/worker.rb
CHANGED
@@ -31,7 +31,7 @@ module Backburner
|
|
31
31
|
|
32
32
|
return nil unless res # stop if hook is false
|
33
33
|
|
34
|
-
data = { :class => job_class.name, :args => args }
|
34
|
+
data = { :class => job_class.name, :args => args, :ttr => ttr }
|
35
35
|
queue = opts[:queue] && (Proc === opts[:queue] ? opts[:queue].call(job_class) : opts[:queue])
|
36
36
|
|
37
37
|
begin
|
@@ -126,9 +126,14 @@ module Backburner
|
|
126
126
|
# @example
|
127
127
|
# @worker.work_one_job
|
128
128
|
# @raise [Beaneater::NotConnected] If beanstalk fails to connect multiple times.
|
129
|
-
def work_one_job(conn = connection)
|
129
|
+
def work_one_job(conn = connection, tube_name = nil)
|
130
|
+
if tube_name.nil?
|
131
|
+
self.log_error "Sampling tube, this is bad practice for Allq"
|
132
|
+
tube_name = @tube_names.sample
|
133
|
+
end
|
134
|
+
|
130
135
|
begin
|
131
|
-
job = reserve_job(conn)
|
136
|
+
job = reserve_job(conn, tube_name)
|
132
137
|
rescue Exception => e
|
133
138
|
self.log_error "Sleeping"
|
134
139
|
self.log_error "Exception: #{e.full_message}"
|
@@ -158,8 +163,6 @@ module Backburner
|
|
158
163
|
retry_status = "failed: attempt #{num_retries+1} of #{max_job_retries+1}"
|
159
164
|
retry_delay = resolve_retry_delay(job.job_class)
|
160
165
|
delay = resolve_retry_delay_proc(job.job_class).call(retry_delay, num_retries) rescue retry_delay
|
161
|
-
puts "num_retries = #{num_retries}"
|
162
|
-
puts "max_job_retries = #{max_job_retries}"
|
163
166
|
|
164
167
|
if num_retries + 1 > max_job_retries
|
165
168
|
job.bury
|
@@ -185,8 +188,8 @@ module Backburner
|
|
185
188
|
end
|
186
189
|
|
187
190
|
# Reserve a job from the watched queues
|
188
|
-
def reserve_job(conn, reserve_timeout = Backburner.configuration.reserve_timeout)
|
189
|
-
job = conn.get(
|
191
|
+
def reserve_job(conn, tube_name, reserve_timeout = Backburner.configuration.reserve_timeout)
|
192
|
+
job = conn.get(tube_name)
|
190
193
|
return nil if job.nil? || job.body == nil?
|
191
194
|
Backburner::Job.new(job)
|
192
195
|
end
|
@@ -58,7 +58,7 @@ module Backburner
|
|
58
58
|
loop do
|
59
59
|
begin
|
60
60
|
break if @in_shutdown
|
61
|
-
work_one_job(memo_connection)
|
61
|
+
work_one_job(memo_connection, tube_name)
|
62
62
|
rescue => e
|
63
63
|
log_error("Exception caught in thread pool loop. Continuing. -> #{e.message}\nBacktrace: #{e.backtrace}")
|
64
64
|
end
|
@@ -210,17 +210,13 @@ module Backburner
|
|
210
210
|
puts "Run while can"
|
211
211
|
while @garbage_after.nil? or @garbage_after > @runs
|
212
212
|
@runs += 1 # FIXME: Likely race condition
|
213
|
-
|
214
|
-
# Wait a second if we didn't find a job
|
215
|
-
unless ran_job
|
216
|
-
puts "sleeping"
|
217
|
-
sleep(rand() * 3)
|
218
|
-
end
|
213
|
+
work_one_job(conn, @watched_tube_name)
|
219
214
|
end
|
220
215
|
end
|
221
216
|
|
222
217
|
# Shortcut for watching a tube on our beanstalk connection
|
223
218
|
def watch_tube(name, conn = connection)
|
219
|
+
@watched_tube_name = name
|
224
220
|
# No op for allq
|
225
221
|
end
|
226
222
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: backburner-allq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.24
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Malcolm
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: allq_rest
|