backburner 1.3.1 → 1.4.0

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
  SHA1:
3
- metadata.gz: ffcc49440304bb0d25a3710a3d94442fd1881f51
4
- data.tar.gz: 2e9318efc9a04979135fecc8edfce4e8c8912386
3
+ metadata.gz: c37d62cede36418881281ed1e7da9293db41cc6d
4
+ data.tar.gz: 2348422b939c94a4fa7d2ed62bae148eac97d78f
5
5
  SHA512:
6
- metadata.gz: caa6aa25343e41b2e8097be38d6b5679f304b9f417f2b0559e085caa2165660fc3ab132f5a920a49360faf16629b84b2d1b740ddf8332b0106df0437458a6f40
7
- data.tar.gz: 457cb6f9ce73c900e0c54face79f78c8f0f6a89b1462580208f5afa9450f17c717fd7b2dd5701299addb334e260e55baa5c5360583867268c9f4ea921c94e38b
6
+ metadata.gz: ef295e9609ba6e52dea4c468dbcdc8b152ece6ef77d7202349aa49b9f496beee8cf71712982f3d248d80e8f17491b21810351a4c9912fd35e9a204878a6827ba
7
+ data.tar.gz: 63751243abb07484e4638cfb51832063b5a3f2c0cd8eb24e8b55f241b0fa68aff8c80690bbd759790c66797356205a6b0c04a72503bf40ebf0e9323e959982f4
@@ -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:
@@ -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 = ["beanstalk://127.0.0.1", "..."]
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 such as 'beanstalk://127.0.0.1' or an array of addresses. |
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
 
@@ -23,5 +23,4 @@ Gem::Specification.new do |s|
23
23
  s.add_development_dependency 'rake'
24
24
  s.add_development_dependency 'minitest', '3.2.0'
25
25
  s.add_development_dependency 'mocha'
26
- s.add_development_dependency 'byebug'
27
26
  end
@@ -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)
@@ -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 : JSON.parse(task.body)
25
- @name, @args = body["class"], body["args"]
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
 
@@ -1,3 +1,3 @@
1
1
  module Backburner
2
- VERSION = "1.3.1"
2
+ VERSION = "1.4.0"
3
3
  end
@@ -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
- response = tube.put(data.to_json, :pri => pri, :delay => delay, :ttr => ttr)
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
@@ -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
- @task_body = { "class" => "NewsletterSender", "args" => ["foo@bar.com", "bar@foo.com"] }
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
- it "should create job with correct task data" do
23
- @job = Backburner::Job.new(@task)
24
- assert_equal @task, @job.task
25
- assert_equal ["class", "args"], @job.body.keys
26
- assert_equal @task_body["class"], @job.name
27
- assert_equal @task_body["args"], @job.args
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
 
@@ -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, &block)
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, JSON.parse(@res.body)
100
+ yield @res, Backburner.configuration.job_parser_proc.call(@res.body)
101
101
  ensure
102
102
  connection.close if connection
103
103
  end
@@ -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
@@ -96,6 +96,7 @@ describe "Backburner::Workers::Forking module" do
96
96
 
97
97
  after do
98
98
  @templogger.close
99
+ Backburner.configuration.logger = nil
99
100
  clear_jobs!('response')
100
101
  clear_jobs!('bar.foo.1', 'bar.foo.2', 'bar.foo.3', 'bar.foo.4', 'bar.foo.5')
101
102
  end
@@ -54,6 +54,8 @@ describe "Backburner::Workers::Threading worker" do
54
54
  before do
55
55
  @worker = @worker_class.new(["foo:3"])
56
56
  capture_stdout { @worker.prepare }
57
+ $worker_test_count = 0
58
+ $worker_success = false
57
59
  end
58
60
 
59
61
  it 'runs work_on_job per thread' do
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.3.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: 2016-10-02 00:00:00.000000000 Z
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.4.8
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