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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 961c84a21c68a6bbe287105030dcbcf73e50177d647321dc410786b417ba653c
4
- data.tar.gz: bee092eb96d993ee4b34b4c1e9fa671cc92e4a3316179890be130dbe14cc70f1
3
+ metadata.gz: ca025bad38a673fdca1c9649c0eb697f0a25f38e9b9181c609c242e2cbc694e9
4
+ data.tar.gz: e1a608abe130c76a3d105c5b28d221263c31c264e425306d2fb86b91c63f2b90
5
5
  SHA512:
6
- metadata.gz: a09fd305b986a90330434db34e13e961f4f6878bff406348fb246f03ac0a3e0b9b8216862128c62005e5b25a4338371cb341e57133aadaa1e3187066fee8698e
7
- data.tar.gz: 12fd13a7430682a5021d16ad32c7f3be1f39767413feeb2a96a7335c465d3639dfbd47905f43249aae27d23030c27a284fce36d098f7b6f396ac789182330efe
6
+ metadata.gz: 6e36f0d3d7c633705f9c51632b34927d1ce790888544690e1c862a1d30f3e8a783209863771a95b6c4fb20556890a1083691d6a5cde317d330248ad1c88f2bc0
7
+ data.tar.gz: a92844eb1114d9afec02017ce932cfc0ab7510125250a9e38908106369ed1b6613ca72a4cf2a5ce97cf4aaf3f7963a4c468aa7a0a7323dd26e3679678100d8d4
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in backburner.gemspec
4
4
  gemspec
5
+
6
+
data/deploy.sh CHANGED
@@ -1,3 +1,3 @@
1
1
  echo "Did you update the version?"
2
2
  gem build backburner-allq.gemspec
3
- gem push backburner-allq-1.0.19.gem
3
+ gem push backburner-allq-1.0.24.gem
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] || 600
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] || 600
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]
@@ -22,7 +22,7 @@ module Backburner
22
22
 
23
23
  def initialize
24
24
  @allq_url = "allq://127.0.0.1:8091"
25
- @tube_namespace = "backallq"
25
+ @tube_namespace = "backburner"
26
26
  @namespace_separator = "."
27
27
  @default_priority = 5
28
28
  @respond_timeout = 120
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Backburner
2
- VERSION = "1.0.19"
2
+ VERSION = "1.0.24"
3
3
  end
@@ -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(@tube_names.sample)
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
- ran_job = work_one_job(conn)
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.19
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-02-13 00:00:00.000000000 Z
11
+ date: 2021-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: allq_rest