backburner 1.8.0 → 1.9.0

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.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +24 -4
  3. data/README.md +70 -14
  4. data/lib/active_job/queue_adapters/backburner_adapter.rb +9 -2
  5. data/lib/backburner/cli.rb +1 -1
  6. data/lib/backburner/enqueue_pool.rb +2 -0
  7. data/lib/backburner/performable.rb +28 -3
  8. data/lib/backburner/version.rb +1 -1
  9. data/lib/backburner/worker.rb +38 -4
  10. data/lib/backburner/workers/threading.rb +16 -0
  11. data/lib/backburner/workers/threads_on_fork.rb +1 -0
  12. metadata +8 -82
  13. data/.github/workflows/ci.yml +0 -45
  14. data/.github/workflows/github-release.yml +0 -58
  15. data/.github/workflows/release.yml +0 -221
  16. data/.gitignore +0 -17
  17. data/CONTRIBUTING.md +0 -37
  18. data/Gemfile +0 -7
  19. data/Rakefile +0 -17
  20. data/TODO +0 -4
  21. data/backburner.gemspec +0 -31
  22. data/examples/custom.rb +0 -25
  23. data/examples/demo.rb +0 -60
  24. data/examples/god.rb +0 -46
  25. data/examples/hooked.rb +0 -87
  26. data/examples/retried.rb +0 -31
  27. data/examples/simple.rb +0 -43
  28. data/examples/stress.rb +0 -31
  29. data/test/active_job_adapter_test.rb +0 -24
  30. data/test/async_proxy_test.rb +0 -36
  31. data/test/back_burner_test.rb +0 -101
  32. data/test/connection_test.rb +0 -201
  33. data/test/fixtures/active_job_app.rb +0 -53
  34. data/test/fixtures/active_jobs.rb +0 -11
  35. data/test/fixtures/autoload/test_broken_name_job.rb +0 -4
  36. data/test/fixtures/autoload/test_broken_no_method_job.rb +0 -4
  37. data/test/fixtures/autoload/test_broken_require_job.rb +0 -4
  38. data/test/fixtures/autoload/test_broken_runtime_job.rb +0 -4
  39. data/test/fixtures/autoload/test_broken_syntax_job.rb +0 -4
  40. data/test/fixtures/autoload/test_broken_timeout_job.rb +0 -4
  41. data/test/fixtures/autoload/test_same_name_job.rb +0 -5
  42. data/test/fixtures/hooked.rb +0 -122
  43. data/test/fixtures/test_fork_jobs.rb +0 -77
  44. data/test/fixtures/test_forking_jobs.rb +0 -56
  45. data/test/fixtures/test_jobs.rb +0 -140
  46. data/test/fixtures/test_queue_settings.rb +0 -54
  47. data/test/helpers/templogger.rb +0 -22
  48. data/test/helpers_test.rb +0 -462
  49. data/test/hooks_test.rb +0 -112
  50. data/test/job_test.rb +0 -207
  51. data/test/logger_test.rb +0 -71
  52. data/test/performable_test.rb +0 -138
  53. data/test/queue_test.rb +0 -132
  54. data/test/test_helper.rb +0 -182
  55. data/test/worker_test.rb +0 -502
  56. data/test/workers/forking_worker_test.rb +0 -199
  57. data/test/workers/simple_worker_test.rb +0 -622
  58. data/test/workers/threading_worker_test.rb +0 -125
  59. data/test/workers/threads_on_fork_worker_test.rb +0 -751
data/examples/simple.rb DELETED
@@ -1,43 +0,0 @@
1
- $:.unshift "lib"
2
- require 'backburner'
3
-
4
- class User
5
- include Backburner::Performable
6
- attr_accessor :id, :name
7
-
8
- def self.first
9
- User.find(3, "John")
10
- end
11
-
12
- def self.find(id, name="Fetched")
13
- User.new(id, name)
14
- end
15
-
16
- def initialize(id, name)
17
- @id, @name = id, name
18
- end
19
-
20
- def hello(x, y)
21
- puts "User(id=#{id}) #hello args: [#{x}, #{y}] (Instance method)"
22
- end
23
-
24
- def self.foo(x, y)
25
- puts "User #foo args [#{x}, #{y}] (Class method)"
26
- end
27
- end
28
-
29
- # Configure Backburner
30
- Backburner.configure do |config|
31
- config.beanstalk_url = "beanstalk://127.0.0.1"
32
- config.tube_namespace = "demo.production"
33
- config.on_error = lambda { |e| puts "HEY!!! #{e.class}" }
34
- end
35
-
36
- # Enqueue tasks
37
- @user = User.first
38
- @user.async(:pri => 1000).hello("foo", "bar")
39
- User.async.foo("bar", "baz")
40
-
41
- # Run work
42
- # Backburner.default_queues << "user"
43
- Backburner.work
data/examples/stress.rb DELETED
@@ -1,31 +0,0 @@
1
- $:.unshift "lib"
2
- require 'backburner'
3
-
4
- $values = []
5
-
6
- # Define ruby job
7
- class TestJob
8
- include Backburner::Queue
9
- queue "test-job"
10
-
11
- def self.perform(value)
12
- puts "[TestJob] Running perform with args: [#{value}]"
13
- $values << value
14
- puts "#{$values.size} total jobs processed"
15
- end
16
- end
17
-
18
- # Configure Backburner
19
- Backburner.configure do |config|
20
- config.beanstalk_url = "beanstalk://127.0.0.1"
21
- config.tube_namespace = "demo.production"
22
- end
23
-
24
- # Enqueue tasks
25
- 1.upto(1000) do |i|
26
- Backburner.enqueue TestJob, i
27
- end
28
-
29
- # Work tasks using threads_on_fork worker
30
- # twitter tube will have 10 threads, garbage after 1000 executions and retry jobs 1 times.
31
- Backburner.work("test-job:10:100:1", :worker => Backburner::Workers::ThreadsOnFork)
@@ -1,24 +0,0 @@
1
- require File.expand_path('../test_helper', __FILE__)
2
- require 'open3'
3
- require 'rbconfig'
4
-
5
- describe "Backburner as the Active Job adapter" do
6
- %w(active_job_first backburner_first active_job_only).each do |order|
7
- it "enqueues and works jobs when the app requires #{order.tr('_', ' ')}" do
8
- namespace = "demo.test.active_job.#{Process.pid}.#{order}"
9
- app = File.expand_path('../fixtures/active_job_app.rb', __FILE__)
10
- out, status = Open3.capture2e(RbConfig.ruby, '-w', '-I', File.expand_path('../../lib', __FILE__), app, namespace, order)
11
- assert status.success?, out
12
- # only backburner's own files: RubyGems can warn about its own
13
- refute_match(/circular require considered harmful - #{Regexp.escape(File.expand_path('../../lib', __FILE__))}\//, out)
14
- result = JSON.parse(out.lines.last)
15
-
16
- tube = "#{namespace}.adapter"
17
- assert_equal({ 'tube' => tube, 'pri' => 7, 'state' => 'ready', 'delay' => 0 }, result['jobs']['now'])
18
- assert_equal({ 'tube' => tube, 'pri' => 3, 'state' => 'ready', 'delay' => 0 }, result['jobs']['urgent'])
19
- # wait: 3 reaches the adapter a little under 3 seconds ahead: rounded up, so it doesn't run early
20
- assert_equal({ 'tube' => tube, 'pri' => 7, 'state' => 'delayed', 'delay' => 3 }, result['jobs']['later'])
21
- assert_equal %w(later now urgent), result['performed']
22
- end
23
- end
24
- end
@@ -1,36 +0,0 @@
1
- require File.expand_path('../test_helper', __FILE__)
2
-
3
- class AsyncUser; end
4
-
5
- describe "Backburner::AsyncProxy class" do
6
- before do
7
- Backburner.default_queues.clear
8
- clear_jobs!(Backburner.configuration.primary_queue)
9
- end
10
-
11
- describe "for method_missing enqueue" do
12
- should "enqueue job onto worker with no args" do
13
- @async = Backburner::AsyncProxy.new(AsyncUser, 10, :pri => 1000, :ttr => 100)
14
- @async.foo
15
- pop_one_job do |job, body|
16
- assert_equal "AsyncUser", body["class"]
17
- assert_equal [10, "foo"], body["args"]
18
- assert_equal 100, job.ttr
19
- assert_equal 1000, job.pri
20
- job.delete
21
- end
22
- end
23
-
24
- should "enqueue job onto worker with args" do
25
- @async = Backburner::AsyncProxy.new(AsyncUser, 10, :pri => 1000, :ttr => 100)
26
- @async.bar(1, 2, 3)
27
- pop_one_job do |job, body|
28
- assert_equal "AsyncUser", body["class"]
29
- assert_equal [10, "bar", 1, 2, 3], body["args"]
30
- assert_equal 100, job.ttr
31
- assert_equal 1000, job.pri
32
- job.delete
33
- end
34
- end
35
- end # method_missing
36
- end # AsyncProxy
@@ -1,101 +0,0 @@
1
- require File.expand_path('../test_helper', __FILE__)
2
-
3
- $backburner_sum = 0
4
- $backburner_numbers = []
5
-
6
- class TestBackburnerJob
7
- include Backburner::Queue
8
- queue "test.jobber"
9
-
10
- def self.perform(value, number)
11
- $backburner_sum += value
12
- $backburner_numbers << number
13
- end
14
- end
15
-
16
- class TestWorker < Backburner::Worker; end
17
-
18
- describe "Backburner module" do
19
- before { Backburner.default_queues.clear }
20
-
21
- describe "for enqueue method" do
22
- before do
23
- Backburner.enqueue TestBackburnerJob, 5, 6
24
- Backburner.enqueue TestBackburnerJob, 15, 10
25
- silenced(2) do
26
- worker = Backburner::Workers::Simple.new('test.jobber')
27
- worker.prepare
28
- 2.times { worker.work_one_job }
29
- end
30
- end
31
-
32
- it "can run jobs using #run method" do
33
- assert_equal 20, $backburner_sum
34
- assert_same_elements [6, 10], $backburner_numbers
35
- end
36
- end # enqueue
37
-
38
- describe "for work method" do
39
- it "invokes worker simple start" do
40
- Backburner::Workers::Simple.expects(:start).with(["foo", "bar"])
41
- Backburner.work("foo", "bar")
42
- end
43
-
44
- it "invokes other worker if specified in configuration" do
45
- Backburner.configure { |config| config.default_worker = TestWorker }
46
- TestWorker.expects(:start).with(["foo", "bar"])
47
- Backburner.work("foo", "bar")
48
- end
49
-
50
- it "invokes other worker if specified in work method as options" do
51
- TestWorker.expects(:start).with(["foo", "bar"])
52
- Backburner.work("foo", "bar", :worker => TestWorker)
53
- end
54
-
55
- it "invokes worker start with no args" do
56
- Backburner::Workers::Simple.expects(:start).with([])
57
- Backburner.work
58
- end
59
- end # work!
60
-
61
- describe "for configuration" do
62
- it "remembers the tube_namespace" do
63
- assert_equal "demo.test", Backburner.configuration.tube_namespace
64
- end
65
-
66
- it "remembers the namespace_separator" do
67
- assert_equal ".", Backburner.configuration.namespace_separator
68
- end
69
-
70
- it "disallows a reserved separator" do
71
- assert_raises RuntimeError do
72
- Backburner.configuration.namespace_separator = ':'
73
- end
74
- end
75
-
76
- it "reads enqueue_connection_max_idle as seconds" do
77
- max_idle = Backburner.configuration.enqueue_connection_max_idle
78
- Backburner.configuration.enqueue_connection_max_idle = "30"
79
- assert_equal 30.0, Backburner.configuration.enqueue_connection_max_idle
80
- Backburner.configuration.enqueue_connection_max_idle = 1
81
- assert_equal 1.0, Backburner.configuration.enqueue_connection_max_idle
82
- Backburner.configuration.enqueue_connection_max_idle = nil
83
- assert_nil Backburner.configuration.enqueue_connection_max_idle
84
- assert_raises(ArgumentError) { Backburner.configuration.enqueue_connection_max_idle = "a minute" }
85
- ensure
86
- Backburner.configuration.enqueue_connection_max_idle = max_idle
87
- end
88
- end # configuration
89
-
90
- describe "for default_queues" do
91
- it "supports assignment" do
92
- Backburner.default_queues << "foo"
93
- Backburner.default_queues << "bar"
94
- assert_same_elements ["foo", "bar"], Backburner.default_queues
95
- end
96
- end
97
-
98
- after do
99
- Backburner.configure { |config| config.default_worker = Backburner::Workers::Simple }
100
- end
101
- end # Backburner
@@ -1,201 +0,0 @@
1
- require File.expand_path('../test_helper', __FILE__)
2
-
3
- describe "Backburner::Connection class" do
4
- describe "for initialize with single url" do
5
- before do
6
- @connection = Backburner::Connection.new("beanstalk://127.0.0.1")
7
- end
8
-
9
- it "should store url in accessor" do
10
- assert_equal "beanstalk://127.0.0.1", @connection.url
11
- end
12
-
13
- it "should setup beanstalk connection" do
14
- assert_kind_of Beaneater, @connection.beanstalk
15
- end
16
- end # initialize single connection
17
-
18
- describe "for initialize with url" do
19
- it "should delegate the address url correctly" do
20
- @connection = Backburner::Connection.new("beanstalk://127.0.0.1")
21
- connection = @connection.beanstalk.connection
22
- assert_equal '127.0.0.1:11300', connection.address
23
- end
24
- end # initialize
25
-
26
- describe "for bad uri" do
27
- it "should raise a BadUrl" do
28
- assert_raises(Backburner::Connection::BadURL) {
29
- @connection = Backburner::Connection.new("fake://foo")
30
- }
31
- end
32
- end
33
-
34
- describe "for initialize with on_reconnect block" do
35
- it "should store the block for use upon reconnect" do
36
- callback = proc {}
37
- connection = Backburner::Connection.new('beanstalk://127.0.0.1', &callback)
38
- assert_equal callback, connection.on_reconnect
39
- end
40
- end
41
-
42
- describe "dealing with connecting and reconnecting" do
43
- before do
44
- @connection = Backburner::Connection.new('beanstalk://127.0.0.1')
45
- end
46
-
47
- it "should know if its connection is open" do
48
- assert_equal true, @connection.connected?
49
- @connection.close
50
- assert_equal false, @connection.connected?
51
- end
52
-
53
- it "should be able to attempt reconnecting to beanstalk" do
54
- @connection.close
55
- assert_equal false, @connection.connected?
56
- @connection.reconnect!
57
- assert_equal true, @connection.connected?
58
- end
59
-
60
- it "should allow for retryable commands" do
61
- @result = false
62
- @connection.close
63
- @connection.retryable { @result = true }
64
- assert_equal true, @result
65
- end
66
-
67
- it "should provide a hook when a retryable command successfully retries" do
68
- @result = false
69
- @retried = false
70
- @connection.close
71
- callback = proc { @result = true }
72
- @connection.retryable(:on_retry => callback) do
73
- unless @retried
74
- @retried = true
75
- raise Beaneater::NotConnected.new
76
- end
77
- end
78
- assert_equal true, @result
79
- end
80
-
81
- it "should provide a hook when the connection successfully reconnects" do
82
- reconnected = false
83
- retried = false
84
- @connection.close
85
- @connection.on_reconnect = proc { reconnected = true }
86
- @connection.retryable do
87
- unless retried
88
- retried = true
89
- raise Beaneater::NotConnected.new
90
- end
91
- end
92
- assert_equal true, reconnected
93
- end
94
-
95
- it "should call the on_reconnect hook before the on_retry hook" do
96
- @result = []
97
- @retried = false
98
- @connection.close
99
- @connection.on_reconnect = proc { @result << "reconnect" }
100
- on_retry = proc { @result << "retry" }
101
- @connection.retryable(:on_retry => on_retry) do
102
- unless @retried
103
- @retried = true
104
- raise Beaneater::NotConnected.new
105
- end
106
- end
107
- assert_equal %w(reconnect retry), @result
108
- end
109
-
110
- describe "ensuring the connection is open" do
111
- it "should reattempt the connection to beanstalk several times" do
112
- stats = @connection.stats
113
- simulate_disconnect(@connection)
114
- new_connection = Beaneater.new('127.0.0.1:11300')
115
- Beaneater.expects(:new).twice.raises(Beaneater::NotConnected).then.returns(new_connection)
116
- @connection.tubes
117
- assert_equal true, @connection.connected?
118
- end
119
-
120
- it "should not attempt reconnecting if the current connection is open" do
121
- assert_equal true, @connection.connected?
122
- Beaneater.expects(:new).never
123
- @connection.tubes
124
- end
125
-
126
- describe "when reconnecting is successful" do
127
- it "should allow for a callback" do
128
- @result = false
129
- simulate_disconnect(@connection)
130
- @connection.on_reconnect = proc { @result = true }
131
- @connection.tubes
132
- assert_equal true, @result
133
- end
134
-
135
- it "should pass self to the callback" do
136
- result = nil
137
- simulate_disconnect(@connection)
138
- @connection.on_reconnect = lambda { |conn| result = conn }
139
- @connection.tubes
140
- assert_equal result, @connection
141
- end
142
- end
143
- end
144
-
145
- describe "when unable to ensure its connected" do
146
- it "should raise Beaneater::NotConnected" do
147
- Beaneater.stubs(:new).raises(Beaneater::NotConnected)
148
- simulate_disconnect(@connection, 1) # since we're stubbing Beaneater.new above we only to simlulate the disconnect of our current connection
149
- assert_raises Beaneater::NotConnected do
150
- @connection.tubes
151
- end
152
- end
153
- end
154
-
155
- describe "when a reconnect fails" do
156
- it "should reconnect on the next call once beanstalkd is back" do
157
- back_up = Beaneater.new('127.0.0.1:11300')
158
- Beaneater.expects(:new).twice.raises(Beaneater::NotConnected).then.returns(back_up)
159
- assert_raises(Beaneater::NotConnected) { @connection.reconnect! }
160
- assert_equal false, @connection.connected?
161
- assert_kind_of Array, @connection.tubes.all
162
- assert_equal true, @connection.connected?
163
- end
164
- end
165
-
166
- describe "when using the retryable method" do
167
- it "should raise Beaneater::NotConnected once the retries are used up" do
168
- attempts = 0
169
- assert_raises Beaneater::NotConnected do
170
- @connection.retryable(max_retries: 1, retry_delay: 0) do
171
- attempts += 1
172
- raise Beaneater::NotConnected
173
- end
174
- end
175
- assert_equal 2, attempts
176
- end
177
-
178
- it "should yield to the block multiple times" do
179
- expected = 2
180
- retry_count = 0
181
- @connection.retryable(max_retries: expected) do
182
- if retry_count < 2
183
- retry_count += 1
184
- raise Beaneater::NotConnected
185
- end
186
- end
187
- assert_equal expected, retry_count
188
- end
189
- end
190
- end
191
-
192
- describe "for delegated methods" do
193
- before do
194
- @connection = Backburner::Connection.new("beanstalk://127.0.0.1")
195
- end
196
-
197
- it "delegate methods to beanstalk connection" do
198
- assert_equal "127.0.0.1", @connection.connection.host
199
- end
200
- end # delegator
201
- end # Connection
@@ -1,53 +0,0 @@
1
- # An app using Backburner as its Active Job adapter. active_job_adapter_test.rb runs it in a child process,
2
- # so Active Job (and Active Support) stay out of the suite's own process.
3
- # Arguments: the tube namespace, then which of the two the app requires first (or active_job_only).
4
- require 'json'
5
- require 'logger' # Active Support 6.1 and 7.0 need Logger loaded first (with concurrent-ruby 1.3.5+)
6
-
7
- namespace, order = ARGV
8
- case order
9
- when 'active_job_first' # a Rails app: rails/all, then Bundler.require
10
- require 'active_job'
11
- require 'backburner'
12
- when 'backburner_first'
13
- require 'backburner'
14
- require 'active_job'
15
- when 'active_job_only' # gem 'backburner', require: false: the adapter loads it
16
- require 'active_job'
17
- end
18
-
19
- ActiveJob::Base.logger = Logger.new(nil)
20
- ActiveJob::Base.queue_adapter = :backburner
21
- Backburner.configure do |config|
22
- config.beanstalk_url = "beanstalk://127.0.0.1"
23
- config.tube_namespace = namespace
24
- config.logger = Logger.new(nil)
25
- config.reserve_timeout = 5
26
- end
27
-
28
- $performed = []
29
- class AdapterTestJob < ActiveJob::Base
30
- queue_as :adapter
31
- queue_with_priority 7
32
- def perform(name)
33
- $performed << name
34
- end
35
- end
36
-
37
- enqueued = {
38
- 'now' => AdapterTestJob.perform_later('now'),
39
- 'urgent' => AdapterTestJob.set(priority: 3).perform_later('urgent'),
40
- 'later' => AdapterTestJob.set(wait: 3).perform_later('later')
41
- }
42
- beanstalk = Beaneater.new('127.0.0.1')
43
- jobs = enqueued.map do |name, job|
44
- stats = job.provider_job_id && beanstalk.jobs.find(job.provider_job_id).stats
45
- [name, stats && { 'tube' => stats.tube, 'pri' => stats.pri, 'state' => stats.state, 'delay' => stats.delay }]
46
- end.to_h
47
- beanstalk.close
48
-
49
- worker = Backburner::Workers::Simple.new(['adapter'])
50
- worker.prepare
51
- enqueued.size.times { worker.work_one_job }
52
-
53
- puts JSON.generate('jobs' => jobs, 'performed' => $performed.sort)
@@ -1,11 +0,0 @@
1
- require 'active_job'
2
- require 'active_job/queue_adapters/backburner_adapter'
3
-
4
- ActiveJob::Base.queue_adapter = :backburner
5
- ActiveJob::Base.logger = nil
6
-
7
- class TestJob < ActiveJob::Base
8
- def perform(arg)
9
- true
10
- end
11
- end
@@ -1,4 +0,0 @@
1
- class TestBrokenNameJob
2
- include TestMissingConcern # renamed or removed: NameError for another constant while the file loads
3
- def self.perform(x); end
4
- end
@@ -1,4 +0,0 @@
1
- class TestBrokenNoMethodJob
2
- queue_respond_timout 30 # a typo: NoMethodError while the file loads
3
- def self.perform(x); end
4
- end
@@ -1,4 +0,0 @@
1
- require 'backburner_test_missing_gem' # a gem left out of the bundle: LoadError while the file loads
2
- class TestBrokenRequireJob
3
- def self.perform(x); end
4
- end
@@ -1,4 +0,0 @@
1
- class TestBrokenRuntimeJob
2
- raise ArgumentError, "bad config" # an error of another kind while the file loads (ENV.fetch raising KeyError, say)
3
- def self.perform(x); end
4
- end
@@ -1,4 +0,0 @@
1
- class TestBrokenSyntaxJob
2
- def self.perform(x)
3
- if # a syntax error: SyntaxError while the file loads
4
- end
@@ -1,4 +0,0 @@
1
- class TestBrokenTimeoutJob
2
- raise Timeout::Error, "class body call timed out" # a call in the class body that timed out (Net::OpenTimeout is a Timeout::Error)
3
- def self.perform(x); end
4
- end
@@ -1,5 +0,0 @@
1
- module TestOtherNamespace; end
2
- class TestSameNameJob
3
- OTHER = TestOtherNamespace::TestSameNameJob # NameError for a constant of the same name in another module
4
- def self.perform(x); end
5
- end
@@ -1,122 +0,0 @@
1
- $hooked_fail_count = 0
2
- class HookFailError < RuntimeError; end
3
-
4
- class HookedObjectBeforeEnqueueFail
5
- include Backburner::Performable
6
-
7
- def self.before_enqueue_abe(*args)
8
- puts "!!before_enqueue_foo!! #{args.inspect}"
9
- end
10
-
11
- def self.before_enqueue_bar(*args)
12
- return false
13
- end
14
- end
15
-
16
-
17
- class HookedObjectAfterEnqueueFail
18
- def self.after_enqueue_abe(*args)
19
- puts "!!after_enqueue_foo!! #{args.inspect}"
20
- end
21
-
22
- def self.after_enqueue_bar(*args)
23
- raise HookFailError, "Fail HookedObjectAfterEnqueueFail"
24
- end
25
- end
26
-
27
- class HookedObjectBeforePerformFail
28
- include Backburner::Performable
29
-
30
- def self.before_perform_abe(*args)
31
- puts "!!before_perform_foo!! #{args.inspect}"
32
- end
33
-
34
- def self.before_perform_foo(*args)
35
- return false
36
- end
37
-
38
- def self.foo(x)
39
- puts "Fail ran!!"
40
- raise HookFailError, "HookedObjectJobFailure on foo!"
41
- end
42
- end
43
-
44
- class HookedObjectAfterPerformFail
45
- def self.after_perform_abe(*args)
46
- puts "!!after_perform_foo!! #{args.inspect}"
47
- end
48
-
49
- def self.after_perform_bar(*args)
50
- raise HookFailError, "Fail HookedObjectAfterEnqueueFail"
51
- end
52
- end
53
-
54
- class HookedObjectJobFailure
55
- def self.foo(x)
56
- raise HookFailError, "HookedObjectJobFailure on foo!"
57
- end
58
- end
59
-
60
- class HookedObjectSuccess
61
- include Backburner::Performable
62
-
63
- def self.before_enqueue_foo(*args)
64
- puts "!!before_enqueue_foo!! #{args.inspect}"
65
- end
66
-
67
- def self.before_enqueue_bar(*args)
68
- puts "!!before_enqueue_bar!! #{args.inspect}"
69
- end
70
-
71
- def self.after_enqueue_foo(*args)
72
- puts "!!after_enqueue_foo!! #{args.inspect}"
73
- end
74
-
75
- def self.after_enqueue_bar(*args)
76
- puts "!!after_enqueue_bar!! #{args.inspect}"
77
- end
78
-
79
- def self.before_perform_foo(*args)
80
- puts "!!before_perform_foo!! #{args.inspect}"
81
- end
82
-
83
- def self.after_perform_foo(*args)
84
- puts "!!after_perform_foo!! #{args.inspect}"
85
- end
86
-
87
- def self.around_perform_bar(*args)
88
- puts "!!BEGIN around_perform_bar!! #{args.inspect}"
89
- yield
90
- puts "!!END around_perform_bar!! #{args.inspect}"
91
- end
92
-
93
- def self.around_perform_cat(*args)
94
- puts "!!BEGIN around_perform_cat!! #{args.inspect}"
95
- yield
96
- puts "!!END around_perform_cat!! #{args.inspect}"
97
- end
98
-
99
- def self.on_failure_foo(ex, *args)
100
- puts "!!on_failure_foo!! #{ex.inspect} #{args.inspect}"
101
- end
102
-
103
- def self.on_bury_foo(*args)
104
- puts "!!on_bury_foo!! #{args.inspect}"
105
- end
106
-
107
- def self.on_retry_foo(retry_count, delay, *args)
108
- puts "!!on_retry_foo!! #{retry_count} #{delay} #{args.inspect}"
109
- end
110
-
111
- def self.foo(x)
112
- $hooked_fail_count += 1
113
- raise HookFailError, "Fail!" if $hooked_fail_count == 1
114
- puts "This is the job running successfully!! #{x.inspect}"
115
- end
116
- end # HookedObjectSuccess
117
-
118
- class HookedWorker < Backburner::Worker
119
- def on_reconnect
120
- puts "!!on_reconnect!!"
121
- end
122
- end