backburner-allq 1.0.34 → 1.0.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 58292818366f9651b49592fa7b035f4da9ab7e3682566346059033639bed4c5b
4
- data.tar.gz: 2124c21a3f66a73373f68550dc9179400c00cf75431de33fc58f1123ed9eaa2b
3
+ metadata.gz: bb5591a73384ecba34a10ba9fb78d56c4c5d8326745f610f240080fefbd28856
4
+ data.tar.gz: c1c96729b87cd70c616085a8ef65f85da3f3697ac8570fb03625db41b82571cd
5
5
  SHA512:
6
- metadata.gz: 5a04ae40e40defa45851012d1d4a626b113b01b1ab34d511835eca6ebcf03625df85e8620edd52c3210bd9b20f997174c1e6176a1463c8463d0c2ed7df343c31
7
- data.tar.gz: f2545dac249dec91798fc81f4fae108aa8928ca6aceffe72345b5388ba5d8757d3ab4a2f6f558add05c69f10217cc98c002c84158b3875e89aef7cd119f5773a
6
+ metadata.gz: ab1b474fef10f4e176ffdfccbd6941c1dccb7039be183a05e065f44f6bc314bbf31785a1f8baefb760af5a806bd17a378f4ca23ab077dfec72f2c0845556e919
7
+ data.tar.gz: 340afa1032f1eedd5b5f441cbfe9343b6ed23d2fcdb0a09400ac365ae882bebe957a10e4e53887f8d35485d6a51cc4a0cd9de6ecf3628ece8cdd82231013c29a
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.34.gem
3
+ gem push backburner-allq-1.0.37.gem
@@ -219,9 +219,6 @@ module Backburner
219
219
 
220
220
  begin
221
221
  Timeout.timeout(10) do
222
- if body && body.to_s.include?('["default"]')
223
- end
224
-
225
222
  if is_parent
226
223
  new_job = build_new_parent_job(body, options)
227
224
  result = @client.parent_job_post(new_job)
@@ -232,18 +229,18 @@ module Backburner
232
229
  raise 'PUT returned nil' if result.nil? || result.to_s == ''
233
230
  end
234
231
  rescue Timeout::Error
235
- puts('ALLQ_PUT_TIMEOUT')
232
+ puts('ALLQ PUT timeout, retrying...')
236
233
  sleep(5)
237
234
  retry_count += 1
238
235
  retry if retry_count < 4
239
- raise 'Failed to put on allq, we are investigating the problem, please try again'
236
+ raise "Failed to put on allq, we are investigating the problem, please try again -> #{body}"
240
237
  rescue StandardError => e
241
- puts('Failed to ALLQ PUT')
238
+ puts('Failed to ALLQ PUT, retrying...')
242
239
  puts(e)
243
240
  retry_count += 1
244
241
  sleep(5)
245
242
  retry if retry_count < 4
246
- raise 'Failed to put on allq, we are investigating the problem, please try again'
243
+ raise "Failed to put on allq, we are investigating the problem, please try again: #{body}"
247
244
  end
248
245
  result
249
246
  end
@@ -257,15 +254,21 @@ module Backburner
257
254
  raw_stats = @admin.stats_get
258
255
  final_stats = {}
259
256
 
260
- raw_stats.each do |agg|
257
+ raw_stats.each_with_index do |agg, i|
261
258
  agg.stats.each do |tube_ref|
262
259
  name = tube_ref.tube
263
- final_stats[name] = {} unless final_stats[name]
260
+ final_stats[name] = {'avg' => 0, 'tps' => 0} unless final_stats[name]
264
261
  final_stats[name]['ready'] = final_stats[name]['ready'].to_i + tube_ref.ready.to_i
265
262
  final_stats[name]['reserved'] = final_stats[name]['reserved'].to_i + tube_ref.reserved.to_i
266
263
  final_stats[name]['delayed'] = final_stats[name]['delayed'].to_i + tube_ref.delayed.to_i
267
264
  final_stats[name]['buried'] = final_stats[name]['buried'].to_i + tube_ref.buried.to_i
268
265
  final_stats[name]['parents'] = final_stats[name]['parents'].to_i + tube_ref.parents.to_i
266
+
267
+
268
+ # Fancy math to calculate averages on the fly
269
+ # https://math.stackexchange.com/questions/106313/regular-average-calculated-accumulatively
270
+ final_stats[name]['avg'] += (tube_ref.avg.to_f - final_stats[name]['avg'].to_f)/(i+1).to_f
271
+ final_stats[name]['tps'] += (tube_ref.tps.to_f - final_stats[name]['tps'].to_f)/(i+1).to_f
269
272
  end
270
273
  end
271
274
  final_stats
@@ -1,3 +1,3 @@
1
1
  module Backburner
2
- VERSION = "1.0.34"
2
+ VERSION = "1.0.37"
3
3
  end
@@ -23,8 +23,13 @@ module Backburner
23
23
  # @example
24
24
  # Backburner::Worker.enqueue NewsletterSender, [self.id, user.id], :ttr => 1000
25
25
  #
26
- def self.enqueue(job_class, args=[], opts={})
27
- opts[:shard_key] = opts[:shard_key].nil? ? "X" : opts[:shard_key].to_s
26
+ def self.enqueue(job_class, args = [], opts = {})
27
+ # Invoke Procs if they are sent
28
+ opts.each_key do |k|
29
+ opts[k] = opts[k].call job_class, args if opts[k].instance_of?(Proc)
30
+ end
31
+
32
+ opts[:shard_key] = opts[:shard_key].nil? ? 'X' : opts[:shard_key].to_s
28
33
  pri = resolve_priority(opts[:pri] || job_class)
29
34
  delay = [0, opts[:delay].to_i].max
30
35
  ttr = resolve_respond_timeout(opts[:ttr] || job_class)
@@ -77,7 +82,7 @@ module Backburner
77
82
  #
78
83
  # @example
79
84
  # Worker.new(['test.job'])
80
- def initialize(tube_names=nil)
85
+ def initialize(tube_names = nil)
81
86
  @connection = new_connection
82
87
  @tube_names = self.process_tube_names(tube_names)
83
88
  register_signal_handlers!
@@ -29,15 +29,15 @@ describe "Backburner::Performable module" do
29
29
 
30
30
  describe "for async instance method" do
31
31
  it "should invoke worker enqueue" do
32
- Backburner::Worker.expects(:enqueue).with(PerformableTestObj, [56, :foo, true, false], has_entries(:pri => 5000, :queue => "foo"))
33
- PerformableTestObj.new.async(:pri => 5000, :queue => "foo").foo(true, false)
32
+ Backburner::Worker.expects(:enqueue).with(PerformableTestObj, [56, :foo, true, false], has_entries(:pri => 5000, :queue => "foo", :shard_key => "abc"))
33
+ PerformableTestObj.new.async(:pri => 5000, :queue => "foo", :shard_key => "abc").foo(true, false)
34
34
  end
35
35
  end # async instance
36
36
 
37
37
  describe "for async class method" do
38
38
  it "should invoke worker enqueue" do
39
- Backburner::Worker.expects(:enqueue).with(PerformableTestObj, [nil, :bar, true, false], has_entries(:pri => 5000, :queue => "foo"))
40
- PerformableTestObj.async(:pri => 5000, :queue => "foo").bar(true, false)
39
+ Backburner::Worker.expects(:enqueue).with(PerformableTestObj, [nil, :bar, true, false], has_entries(:pri => 5000, :queue => "foo", :shard_key => "abc"))
40
+ PerformableTestObj.async(:pri => 5000, :queue => "foo", :shard_key => "abc").bar(true, false)
41
41
  end
42
42
  end # async class
43
43
 
@@ -53,16 +53,16 @@ describe "Backburner::Performable module" do
53
53
 
54
54
  describe "for handle_asynchronously class method" do
55
55
  it "should automagically asynchronously proxy calls to the method" do
56
- Backburner::Performable.handle_asynchronously(AutomagicTestObj, :qux, :pri => 5000, :queue => "qux")
56
+ Backburner::Performable.handle_asynchronously(AutomagicTestObj, :qux, :pri => 5000, :queue => "qux", :shard_key => "abc")
57
57
 
58
- Backburner::Worker.expects(:enqueue).with(AutomagicTestObj, [56, :qux_without_async, true, false], has_entries(:pri => 5000, :queue => "qux"))
58
+ Backburner::Worker.expects(:enqueue).with(AutomagicTestObj, [56, :qux_without_async, true, false], has_entries(:pri => 5000, :queue => "qux", :shard_key => "abc"))
59
59
  AutomagicTestObj.new.qux(true, false)
60
60
  end
61
61
 
62
62
  it "should work for class methods, too" do
63
- Backburner::Performable.handle_static_asynchronously(AutomagicTestObj, :garply, :pri => 5000, :queue => "garply")
63
+ Backburner::Performable.handle_static_asynchronously(AutomagicTestObj, :garply, :pri => 5000, :queue => "garply", :shard_key => "abc")
64
64
 
65
- Backburner::Worker.expects(:enqueue).with(AutomagicTestObj, [nil, :garply_without_async, true, false], has_entries(:pri => 5000, :queue => "garply"))
65
+ Backburner::Worker.expects(:enqueue).with(AutomagicTestObj, [nil, :garply_without_async, true, false], has_entries(:pri => 5000, :queue => "garply", :shard_key => "abc"))
66
66
  AutomagicTestObj.garply(true, false)
67
67
  end
68
68
 
@@ -74,14 +74,14 @@ describe "Backburner::Performable module" do
74
74
  end
75
75
 
76
76
  it "should be available for instance methods on any class that includes the Performable module" do
77
- AsyncInstanceMethodsTestObj.handle_asynchronously :foo, pri: 5000, queue: 'qux'
78
- Backburner::Worker.expects(:enqueue).with(AsyncInstanceMethodsTestObj, [56, :foo_without_async, true, false], has_entries(:pri => 5000, :queue => "qux"))
77
+ AsyncInstanceMethodsTestObj.handle_asynchronously :foo, pri: 5000, queue: 'qux', shard_key: "abc"
78
+ Backburner::Worker.expects(:enqueue).with(AsyncInstanceMethodsTestObj, [56, :foo_without_async, true, false], has_entries(:pri => 5000, :queue => "qux", :shard_key => "abc"))
79
79
  AsyncInstanceMethodsTestObj.new.foo(true, false)
80
80
  end
81
81
 
82
82
  it "should be available for class methods on any class that includes the Performable module" do
83
- AsyncStaticMethodsTestObj.handle_static_asynchronously :bar, pri: 5000, queue: 'garply'
84
- Backburner::Worker.expects(:enqueue).with(AsyncStaticMethodsTestObj, [nil, :bar_without_async, true, false], has_entries(:pri => 5000, :queue => "garply"))
83
+ AsyncStaticMethodsTestObj.handle_static_asynchronously :bar, pri: 5000, queue: 'garply', shard_key: "abc"
84
+ Backburner::Worker.expects(:enqueue).with(AsyncStaticMethodsTestObj, [nil, :bar_without_async, true, false], has_entries(:pri => 5000, :queue => "garply",:shard_key => "abc"))
85
85
  AsyncStaticMethodsTestObj.bar(true, false)
86
86
  end
87
87
  end
data/test/test_helper.rb CHANGED
@@ -12,7 +12,7 @@ require File.expand_path('../helpers/templogger', __FILE__)
12
12
 
13
13
  # Configure Backburner
14
14
  Backburner.configure do |config|
15
- config.beanstalk_url = "beanstalk://127.0.0.1"
15
+ config.allq_url = "allq://127.0.0.1:8091"
16
16
  config.tube_namespace = "demo.test"
17
17
  end
18
18
 
@@ -88,7 +88,7 @@ class MiniTest::Spec
88
88
  end
89
89
 
90
90
  def beanstalk_connection
91
- Backburner::Connection.new(Backburner.configuration.beanstalk_url)
91
+ Backburner::Connection.new(Backburner.configuration.allq_url)
92
92
  end
93
93
 
94
94
  # pop_one_job(tube_name)
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.34
4
+ version: 1.0.37
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-09-21 00:00:00.000000000 Z
11
+ date: 2022-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: allq_rest