backburner 1.3.1 → 1.4.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.
- checksums.yaml +4 -4
- data/.travis.yml +4 -1
- data/CHANGELOG.md +7 -0
- data/README.md +7 -2
- data/backburner.gemspec +0 -1
- data/lib/backburner/configuration.rb +4 -0
- data/lib/backburner/job.rb +4 -3
- data/lib/backburner/version.rb +1 -1
- data/lib/backburner/worker.rb +2 -1
- data/test/job_test.rb +21 -8
- data/test/test_helper.rb +2 -2
- data/test/worker_test.rb +29 -0
- data/test/workers/forking_worker_test.rb +1 -0
- data/test/workers/threading_worker_test.rb +2 -0
- metadata +3 -17
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c37d62cede36418881281ed1e7da9293db41cc6d
|
|
4
|
+
data.tar.gz: 2348422b939c94a4fa7d2ed62bae148eac97d78f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ef295e9609ba6e52dea4c468dbcdc8b152ece6ef77d7202349aa49b9f496beee8cf71712982f3d248d80e8f17491b21810351a4c9912fd35e9a204878a6827ba
|
|
7
|
+
data.tar.gz: 63751243abb07484e4638cfb51832063b5a3f2c0cd8eb24e8b55f241b0fa68aff8c80690bbd759790c66797356205a6b0c04a72503bf40ebf0e9323e959982f4
|
data/.travis.yml
CHANGED
|
@@ -9,11 +9,14 @@ before_install:
|
|
|
9
9
|
- make
|
|
10
10
|
- ./beanstalkd &
|
|
11
11
|
- cd $TRAVIS_BUILD_DIR
|
|
12
|
+
- gem update --system
|
|
13
|
+
- gem update bundler
|
|
14
|
+
install:
|
|
15
|
+
- bundle install
|
|
12
16
|
matrix:
|
|
13
17
|
allow_failures:
|
|
14
18
|
- rvm: rbx-2
|
|
15
19
|
script:
|
|
16
|
-
- bundle install
|
|
17
20
|
- bundle exec rake test
|
|
18
21
|
gemfile: Gemfile
|
|
19
22
|
notifications:
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## Version 1.4.0 (May 13 2017)
|
|
4
|
+
|
|
5
|
+
* Fix unit tests to be more consistent (@eltone)
|
|
6
|
+
* Ensure job supports body hash with symbol keys (@eltone)
|
|
7
|
+
* Add support for custom serialization formats (@eltone)
|
|
8
|
+
* Log the params when a job timeout occurs (@nathantsoi)
|
|
9
|
+
|
|
3
10
|
## Version 1.3.1 (April 21 2016)
|
|
4
11
|
|
|
5
12
|
* Addition of thread-pool-based concurrency (@contentfree)
|
data/README.md
CHANGED
|
@@ -88,7 +88,7 @@ Backburner is extremely simple to setup. Just configure basic settings for backb
|
|
|
88
88
|
|
|
89
89
|
```ruby
|
|
90
90
|
Backburner.configure do |config|
|
|
91
|
-
config.beanstalk_url =
|
|
91
|
+
config.beanstalk_url = "beanstalk://127.0.0.1"
|
|
92
92
|
config.tube_namespace = "some.app.production"
|
|
93
93
|
config.namespace_separator = "."
|
|
94
94
|
config.on_error = lambda { |e| puts e }
|
|
@@ -102,6 +102,9 @@ Backburner.configure do |config|
|
|
|
102
102
|
config.primary_queue = "backburner-jobs"
|
|
103
103
|
config.priority_labels = { :custom => 50, :useless => 1000 }
|
|
104
104
|
config.reserve_timeout = nil
|
|
105
|
+
config.job_serializer_proc = lambda { |body| JSON.dump(body) }
|
|
106
|
+
config.job_parser_proc = lambda { |body| JSON.parse(body) }
|
|
107
|
+
|
|
105
108
|
end
|
|
106
109
|
```
|
|
107
110
|
|
|
@@ -109,7 +112,7 @@ The key options available are:
|
|
|
109
112
|
|
|
110
113
|
| Option | Description |
|
|
111
114
|
| ----------------- | ------------------------------- |
|
|
112
|
-
| `beanstalk_url` | Address
|
|
115
|
+
| `beanstalk_url` | Address for beanstalkd connection i.e 'beanstalk://127.0.0.1' |
|
|
113
116
|
| `tube_namespace` | Prefix used for all tubes related to this backburner queue. |
|
|
114
117
|
| `namespace_separator` | Separator used for namespace and queue name |
|
|
115
118
|
| `on_error` | Lambda invoked with the error whenever any job in the system fails. |
|
|
@@ -123,6 +126,8 @@ The key options available are:
|
|
|
123
126
|
| `primary_queue` | Primary queue used for a job when an alternate queue is not given. |
|
|
124
127
|
| `priority_labels` | Hash of named priority definitions for your app. |
|
|
125
128
|
| `reserve_timeout` | Duration to wait for work from a single server, or nil for forever. |
|
|
129
|
+
| `job_serializer_proc` | Lambda serializes a job body to a string to write to the task |
|
|
130
|
+
| `job_parser_proc` | Lambda parses a task body string to a hash |
|
|
126
131
|
|
|
127
132
|
## Breaking Changes
|
|
128
133
|
|
data/backburner.gemspec
CHANGED
|
@@ -17,6 +17,8 @@ module Backburner
|
|
|
17
17
|
attr_accessor :primary_queue # the general queue
|
|
18
18
|
attr_accessor :priority_labels # priority labels
|
|
19
19
|
attr_accessor :reserve_timeout # duration to wait to reserve on a single server
|
|
20
|
+
attr_accessor :job_serializer_proc # proc to write the job body to a string
|
|
21
|
+
attr_accessor :job_parser_proc # proc to parse a job body from a string
|
|
20
22
|
|
|
21
23
|
def initialize
|
|
22
24
|
@beanstalk_url = "beanstalk://127.0.0.1"
|
|
@@ -34,6 +36,8 @@ module Backburner
|
|
|
34
36
|
@primary_queue = "backburner-jobs"
|
|
35
37
|
@priority_labels = PRIORITY_LABELS
|
|
36
38
|
@reserve_timeout = nil
|
|
39
|
+
@job_serializer_proc = lambda { |body| body.to_json }
|
|
40
|
+
@job_parser_proc = lambda { |body| JSON.parse(body) }
|
|
37
41
|
end
|
|
38
42
|
|
|
39
43
|
def namespace_separator=(val)
|
data/lib/backburner/job.rb
CHANGED
|
@@ -21,8 +21,9 @@ module Backburner
|
|
|
21
21
|
def initialize(task)
|
|
22
22
|
@hooks = Backburner::Hooks
|
|
23
23
|
@task = task
|
|
24
|
-
@body = task.body.is_a?(Hash) ? task.body :
|
|
25
|
-
@name
|
|
24
|
+
@body = task.body.is_a?(Hash) ? task.body : Backburner.configuration.job_parser_proc.call(task.body)
|
|
25
|
+
@name = body["class"] || body[:class]
|
|
26
|
+
@args = body["args"] || body[:args]
|
|
26
27
|
rescue => ex # Job was not valid format
|
|
27
28
|
self.bury
|
|
28
29
|
raise JobFormatInvalid, "Job body could not be parsed: #{ex.inspect}"
|
|
@@ -93,7 +94,7 @@ module Backburner
|
|
|
93
94
|
begin
|
|
94
95
|
Timeout::timeout(secs) { yield }
|
|
95
96
|
rescue Timeout::Error => e
|
|
96
|
-
raise JobTimeout, "#{name} hit #{secs}s timeout.\nbacktrace: #{e.backtrace}"
|
|
97
|
+
raise JobTimeout, "#{name}(#{(@args||[]).join(', ')}) hit #{secs}s timeout.\nbacktrace: #{e.backtrace}"
|
|
97
98
|
end
|
|
98
99
|
end
|
|
99
100
|
|
data/lib/backburner/version.rb
CHANGED
data/lib/backburner/worker.rb
CHANGED
|
@@ -39,7 +39,8 @@ module Backburner
|
|
|
39
39
|
connection = Backburner::Connection.new(Backburner.configuration.beanstalk_url)
|
|
40
40
|
connection.retryable do
|
|
41
41
|
tube = connection.tubes[expand_tube_name(queue || job_class)]
|
|
42
|
-
|
|
42
|
+
serialized_data = Backburner.configuration.job_serializer_proc.call(data)
|
|
43
|
+
response = tube.put(serialized_data, :pri => pri, :delay => delay, :ttr => ttr)
|
|
43
44
|
end
|
|
44
45
|
return nil unless Backburner::Hooks.invoke_hook_events(job_class, :after_enqueue, *args)
|
|
45
46
|
ensure
|
data/test/job_test.rb
CHANGED
|
@@ -15,16 +15,29 @@ describe "Backburner::Job module" do
|
|
|
15
15
|
describe "for initialize" do
|
|
16
16
|
describe "with hash" do
|
|
17
17
|
before do
|
|
18
|
-
@
|
|
19
|
-
@task = stub(:body => @task_body, :ttr => 120, :delete => true, :bury => true)
|
|
18
|
+
@task = stub(:body => task_body, :ttr => 120, :delete => true, :bury => true)
|
|
20
19
|
end
|
|
21
20
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
describe "with string keys" do
|
|
22
|
+
let(:task_body) { { "class" => "NewsletterSender", "args" => ["foo@bar.com", "bar@foo.com"] } }
|
|
23
|
+
it "should create job with correct task data" do
|
|
24
|
+
@job = Backburner::Job.new(@task)
|
|
25
|
+
assert_equal @task, @job.task
|
|
26
|
+
assert_equal ["class", "args"], @job.body.keys
|
|
27
|
+
assert_equal task_body["class"], @job.name
|
|
28
|
+
assert_equal task_body["args"], @job.args
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
describe "with symbol keys" do
|
|
33
|
+
let(:task_body) { { :class => "NewsletterSender", :args => ["foo@bar.com", "bar@foo.com"] } }
|
|
34
|
+
it "should create job with correct task data" do
|
|
35
|
+
@job = Backburner::Job.new(@task)
|
|
36
|
+
assert_equal @task, @job.task
|
|
37
|
+
assert_equal [:class, :args], @job.body.keys
|
|
38
|
+
assert_equal task_body[:class], @job.name
|
|
39
|
+
assert_equal task_body[:args], @job.args
|
|
40
|
+
end
|
|
28
41
|
end
|
|
29
42
|
end # with hash
|
|
30
43
|
|
data/test/test_helper.rb
CHANGED
|
@@ -92,12 +92,12 @@ class MiniTest::Spec
|
|
|
92
92
|
end
|
|
93
93
|
|
|
94
94
|
# pop_one_job(tube_name)
|
|
95
|
-
def pop_one_job(tube_name=Backburner.configuration.primary_queue
|
|
95
|
+
def pop_one_job(tube_name=Backburner.configuration.primary_queue)
|
|
96
96
|
tube_name = [Backburner.configuration.tube_namespace, tube_name].join(".")
|
|
97
97
|
connection = beanstalk_connection
|
|
98
98
|
connection.tubes.watch!(tube_name)
|
|
99
99
|
silenced(3) { @res = connection.tubes.reserve }
|
|
100
|
-
yield @res,
|
|
100
|
+
yield @res, Backburner.configuration.job_parser_proc.call(@res.body)
|
|
101
101
|
ensure
|
|
102
102
|
connection.close if connection
|
|
103
103
|
end
|
data/test/worker_test.rb
CHANGED
|
@@ -125,4 +125,33 @@ describe "Backburner::Worker module" do
|
|
|
125
125
|
assert_equal ['baz', 'bam'], worker.tube_names
|
|
126
126
|
end
|
|
127
127
|
end # tube_names
|
|
128
|
+
|
|
129
|
+
describe "for custom serialization" do
|
|
130
|
+
before do
|
|
131
|
+
Backburner.configure do |config|
|
|
132
|
+
@old_parser = config.job_parser_proc
|
|
133
|
+
@old_serializer = config.job_serializer_proc
|
|
134
|
+
config.job_parser_proc = lambda { |body| Marshal.load(body) }
|
|
135
|
+
config.job_serializer_proc = lambda { |body| Marshal.dump(body) }
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
after do
|
|
140
|
+
clear_jobs!('test-plain')
|
|
141
|
+
Backburner.configure do |config|
|
|
142
|
+
config.job_parser_proc = @old_parser
|
|
143
|
+
config.job_serializer_proc = @old_serializer
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
it "should support enqueuing a job" do
|
|
148
|
+
Backburner::Worker.enqueue TestPlainJob, [7, 9], :ttr => 100, :pri => 2000
|
|
149
|
+
pop_one_job("test-plain") do |job, body|
|
|
150
|
+
assert_equal "TestPlainJob", body[:class]
|
|
151
|
+
assert_equal [7, 9], body[:args]
|
|
152
|
+
assert_equal 100, job.ttr
|
|
153
|
+
assert_equal 2000, job.pri
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
end # custom serialization
|
|
128
157
|
end # Backburner::Worker
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: backburner
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nathan Esquenazi
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2017-05-14 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: beaneater
|
|
@@ -94,20 +94,6 @@ dependencies:
|
|
|
94
94
|
- - ">="
|
|
95
95
|
- !ruby/object:Gem::Version
|
|
96
96
|
version: '0'
|
|
97
|
-
- !ruby/object:Gem::Dependency
|
|
98
|
-
name: byebug
|
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
|
100
|
-
requirements:
|
|
101
|
-
- - ">="
|
|
102
|
-
- !ruby/object:Gem::Version
|
|
103
|
-
version: '0'
|
|
104
|
-
type: :development
|
|
105
|
-
prerelease: false
|
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
-
requirements:
|
|
108
|
-
- - ">="
|
|
109
|
-
- !ruby/object:Gem::Version
|
|
110
|
-
version: '0'
|
|
111
97
|
description: Beanstalk background job processing made easy
|
|
112
98
|
email:
|
|
113
99
|
- nesquena@gmail.com
|
|
@@ -195,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
195
181
|
version: '0'
|
|
196
182
|
requirements: []
|
|
197
183
|
rubyforge_project:
|
|
198
|
-
rubygems_version: 2.
|
|
184
|
+
rubygems_version: 2.6.7
|
|
199
185
|
signing_key:
|
|
200
186
|
specification_version: 4
|
|
201
187
|
summary: Reliable beanstalk background job processing made easy for Ruby and Sinatra
|