backburner 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5cefef513a8a0bdd3a88721c01eb503c01f4aa3c
4
+ data.tar.gz: b9b0506df21468b7496c5a6b7dec90492c0dc899
5
+ SHA512:
6
+ metadata.gz: 0da929c2d10311de013e5b1943754fdeb5dc75e598cb2e52097510827ebf23df93a8cb788be599fbfc54fbf83f3b15637a0c91825cbeb49c3da995a7f734363e
7
+ data.tar.gz: 16783da0512636828941b8a141539c67f4a3dc528f2d0a66e065b4c5c2c3ea710a7c4d658829753362e40f4d3981d6fbb329d4df5c0573d8e006721c5f4692e7
@@ -1,9 +1,20 @@
1
1
  # http://about.travis-ci.org/docs/user/build-configuration/
2
2
  rvm:
3
- - 1.8.7
4
- - 1.9.2
5
3
  - 1.9.3
4
+ - 2.0.0
6
5
  - rbx-19mode
6
+ before_install:
7
+ - curl -L https://github.com/kr/beanstalkd/archive/v1.9.tar.gz | tar xz -C /tmp
8
+ - cd /tmp/beanstalkd-1.9/
9
+ - make
10
+ - ./beanstalkd &
11
+ - cd $TRAVIS_BUILD_DIR
12
+ matrix:
13
+ allow_failures:
14
+ - rvm: rbx-19mode
15
+ script:
16
+ - bundle install
17
+ - bundle exec rake test
7
18
  gemfile: Gemfile
8
19
  notifications:
9
20
  recipients:
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## Version 0.4.4 (October 27 2013)
4
+
5
+ * NEW #51 Added ability to set per-queue default ttr's (Thanks @ryanjohns)
6
+
3
7
  ## Version 0.4.3 (July 19 2013)
4
8
 
5
9
  * FIX #44 Additional fix to issue introduced in 0.4.2
data/HOOKS.md CHANGED
@@ -34,17 +34,21 @@ Hooks are just methods prefixed with the hook type. For example:
34
34
  ```ruby
35
35
  class SomeJob
36
36
  def self.before_perform_log_job(*args)
37
- Logger.info "About to perform #{self} with #{args.inspect}"
37
+ logger.info "About to perform #{self} with #{args.inspect}"
38
38
  end
39
39
 
40
40
  def self.on_failure_bury(e, *args)
41
- Logger.info "Performing #{self} caused an exception (#{e})"
41
+ logger.info "Performing #{self} caused an exception (#{e})"
42
42
  self.bury
43
43
  end
44
44
 
45
45
  def self.perform(*args)
46
46
  # ...
47
47
  end
48
+
49
+ def self.logger
50
+ @_logger ||= Logger.new(STDOUT)
51
+ end
48
52
  end
49
53
  ```
50
54
 
data/README.md CHANGED
@@ -149,6 +149,11 @@ class NewsletterJob
149
149
  def self.queue_priority
150
150
  1000 # most urgent priority is 0
151
151
  end
152
+
153
+ # optional, defaults to respond_timeout
154
+ def self.queue_respond_timeout
155
+ 300 # number of seconds before job times out
156
+ end
152
157
  end
153
158
  ```
154
159
 
@@ -159,6 +164,7 @@ class NewsletterJob
159
164
  include Backburner::Queue
160
165
  queue "newsletter-sender" # defaults to 'backburner-jobs' tube
161
166
  queue_priority 1000 # most urgent priority is 0
167
+ queue_respond_timeout 300 # number of seconds before job times out
162
168
 
163
169
  def self.perform(email, body)
164
170
  NewsletterMailer.deliver_text_to_email(email, body)
@@ -186,6 +192,7 @@ class User
186
192
  include Backburner::Performable
187
193
  queue "user-jobs" # defaults to 'user'
188
194
  queue_priority 500 # most urgent priority is 0
195
+ queue_respond_timeout 300 # number of seconds before job times out
189
196
 
190
197
  def activate(device_id)
191
198
  @device = Device.find(device_id)
@@ -14,6 +14,7 @@ Gem::Specification.new do |s|
14
14
  s.name = "backburner"
15
15
  s.require_paths = ["lib"]
16
16
  s.version = Backburner::VERSION
17
+ s.license = 'MIT'
17
18
 
18
19
  s.add_runtime_dependency 'beaneater', '~> 0.3.1'
19
20
  s.add_runtime_dependency 'dante', '~> 0.1.5'
@@ -116,5 +116,22 @@ module Backburner
116
116
  end
117
117
  end
118
118
 
119
+ # Resolves job respond timeout based on the value given. Can be integer, a class or nothing
120
+ #
121
+ # @example
122
+ # resolve_respond_timeout(1000) => 1000
123
+ # resolve_respond_timeout(FooBar) => <queue respond_timeout>
124
+ # resolve_respond_timeout(nil) => <default respond_timeout>
125
+ #
126
+ def resolve_respond_timeout(ttr)
127
+ if ttr.respond_to?(:queue_respond_timeout)
128
+ resolve_respond_timeout(ttr.queue_respond_timeout)
129
+ elsif ttr.is_a?(Fixnum) # numerical
130
+ ttr
131
+ else # default
132
+ Backburner.configuration.respond_timeout
133
+ end
134
+ end
135
+
119
136
  end # Helpers
120
137
  end # Backburner
@@ -33,6 +33,20 @@ module Backburner
33
33
  @queue_priority
34
34
  end
35
35
  end
36
+
37
+ # Returns or assigns queue respond_timeout for this job
38
+ #
39
+ # @example
40
+ # queue_respond_timeout 120
41
+ # @klass.queue_respond_timeout # => 120
42
+ #
43
+ def queue_respond_timeout(ttr=nil)
44
+ if ttr
45
+ @queue_respond_timeout = ttr
46
+ else # accessor
47
+ @queue_respond_timeout
48
+ end
49
+ end
36
50
  end # ClassMethods
37
51
  end # Queue
38
52
  end # Backburner
@@ -1,3 +1,3 @@
1
1
  module Backburner
2
- VERSION = "0.4.3"
2
+ VERSION = "0.4.4"
3
3
  end
@@ -26,7 +26,7 @@ module Backburner
26
26
  def self.enqueue(job_class, args=[], opts={})
27
27
  pri = resolve_priority(opts[:pri] || job_class)
28
28
  delay = [0, opts[:delay].to_i].max
29
- ttr = opts[:ttr] || Backburner.configuration.respond_timeout
29
+ ttr = resolve_respond_timeout(opts[:ttr] || job_class)
30
30
  res = Backburner::Hooks.invoke_hook_events(job_class, :before_enqueue, *args)
31
31
  return false unless res # stop if hook is false
32
32
  data = { :class => job_class.name, :args => args }
@@ -9,6 +9,7 @@ end
9
9
  class TestJob
10
10
  include Backburner::Queue
11
11
  queue_priority :medium
12
+ queue_respond_timeout 300
12
13
  def self.perform(x, y); $worker_test_count += x + y; end
13
14
  end
14
15
 
@@ -78,8 +78,14 @@ describe "Backburner::Helpers module" do
78
78
  end # expand_tube_name
79
79
 
80
80
  describe "for resolve_priority method" do
81
- before { Backburner.configure { |config| config.default_priority = 1000 } }
82
- after { Backburner.configure { |config| config.priority_labels = Backburner::Configuration::PRIORITY_LABELS } }
81
+ before do
82
+ @original_queue_priority = Backburner.configuration.default_priority
83
+ Backburner.configure { |config| config.default_priority = 1000 }
84
+ end
85
+ after do
86
+ Backburner.configure { |config| config.default_priority = @original_queue_priority }
87
+ Backburner.configure { |config| config.priority_labels = Backburner::Configuration::PRIORITY_LABELS }
88
+ end
83
89
 
84
90
  it "supports fix num priority" do
85
91
  assert_equal 500, resolve_priority(500)
@@ -124,4 +130,35 @@ describe "Backburner::Helpers module" do
124
130
  assert_equal 1000, resolve_priority(nil)
125
131
  end
126
132
  end # resolve_priority
133
+
134
+ describe "for resolve_respond_timeout method" do
135
+ before do
136
+ @original_respond_timeout = Backburner.configuration.respond_timeout
137
+ Backburner.configure { |config| config.respond_timeout = 300 }
138
+ end
139
+ after { Backburner.configure { |config| config.respond_timeout = @original_respond_timeout } }
140
+
141
+ it "supports fix num respond_timeout" do
142
+ assert_equal 500, resolve_respond_timeout(500)
143
+ end
144
+
145
+ it "supports classes which respond to queue_respond_timeout" do
146
+ job = stub(:queue_respond_timeout => 600)
147
+ assert_equal 600, resolve_respond_timeout(job)
148
+ end
149
+
150
+ it "supports classes which returns null queue_respond_timeout" do
151
+ job = stub(:queue_respond_timeout => nil)
152
+ assert_equal 300, resolve_respond_timeout(job)
153
+ end
154
+
155
+ it "supports classes which don't respond to queue_respond_timeout" do
156
+ job = stub(:fake => true)
157
+ assert_equal 300, resolve_respond_timeout(job)
158
+ end
159
+
160
+ it "supports default ttr for null values" do
161
+ assert_equal 300, resolve_respond_timeout(nil)
162
+ end
163
+ end # resolve_respond_timeout
127
164
  end
@@ -31,5 +31,12 @@ describe "Backburner::Queue module" do
31
31
  NestedDemo::TestJobB.queue_priority(1000)
32
32
  assert_equal 1000, NestedDemo::TestJobB.queue_priority
33
33
  end
34
- end # queue
34
+ end # queue_priority
35
+
36
+ describe "for queue_respond_timeout assignment method" do
37
+ it "should allow queue respond_timeout to be assigned" do
38
+ NestedDemo::TestJobB.queue_respond_timeout(300)
39
+ assert_equal 300, NestedDemo::TestJobB.queue_respond_timeout
40
+ end
41
+ end # queue_respond_timeout
35
42
  end # Backburner::Queue
@@ -1,7 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'tempfile'
3
3
  require 'minitest/autorun'
4
- require 'mocha'
4
+ require 'mocha/setup'
5
5
  $:.unshift File.expand_path("../../lib")
6
6
  require 'backburner'
7
7
  require File.expand_path('../helpers/templogger', __FILE__)
@@ -5,7 +5,7 @@ require File.expand_path('../fixtures/hooked', __FILE__)
5
5
  describe "Backburner::Worker module" do
6
6
  before do
7
7
  Backburner.default_queues.clear
8
- clear_jobs!(Backburner.configuration.primary_queue)
8
+ clear_jobs!(Backburner.configuration.primary_queue, "test-plain", "test.bar", "bar.baz.foo")
9
9
  end
10
10
 
11
11
  describe "for enqueue class method" do
@@ -25,7 +25,7 @@ describe "Backburner::Worker module" do
25
25
  assert_equal [3, 4], body["args"]
26
26
  assert_equal 100, job.ttr
27
27
  assert_equal 100, job.pri
28
- end # queue
28
+ end # queue priority
29
29
 
30
30
  it "should support enqueuing job with specified named priority" do
31
31
  Backburner::Worker.enqueue TestJob, [3, 4], :ttr => 100, :pri => 'high'
@@ -34,7 +34,16 @@ describe "Backburner::Worker module" do
34
34
  assert_equal [3, 4], body["args"]
35
35
  assert_equal 100, job.ttr
36
36
  assert_equal 0, job.pri
37
- end # queue
37
+ end # queue named priority
38
+
39
+ it "should support enqueuing job with class queue respond_timeout" do
40
+ Backburner::Worker.enqueue TestJob, [3, 4]
41
+ job, body = pop_one_job
42
+ assert_equal "TestJob", body["class"]
43
+ assert_equal [3, 4], body["args"]
44
+ assert_equal 300, job.ttr
45
+ assert_equal 100, job.pri
46
+ end # queue respond_timeout
38
47
 
39
48
  it "should support enqueuing job with custom queue" do
40
49
  Backburner::Worker.enqueue TestJob, [6, 7], :queue => "test.bar", :pri => 5000
@@ -43,7 +52,7 @@ describe "Backburner::Worker module" do
43
52
  assert_equal [6, 7], body["args"]
44
53
  assert_equal 0, job.delay
45
54
  assert_equal 5000, job.pri
46
- assert_equal Backburner.configuration.respond_timeout, job.ttr
55
+ assert_equal 300, job.ttr
47
56
  end # custom
48
57
 
49
58
  it "should support async job" do
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: backburner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
5
- prerelease:
4
+ version: 0.4.4
6
5
  platform: ruby
7
6
  authors:
8
7
  - Nathan Esquenazi
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-07-19 00:00:00.000000000 Z
11
+ date: 2013-10-27 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: beaneater
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: dante
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,23 +41,20 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rake
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: minitest
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - '='
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - '='
76
67
  - !ruby/object:Gem::Version
@@ -78,17 +69,15 @@ dependencies:
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: mocha
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - '>='
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - '>='
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  description: Beanstalk background job processing made easy
@@ -156,34 +145,28 @@ files:
156
145
  - test/workers/simple_worker_test.rb
157
146
  - test/workers/threads_on_fork_worker_test.rb
158
147
  homepage: http://github.com/nesquena/backburner
159
- licenses: []
148
+ licenses:
149
+ - MIT
150
+ metadata: {}
160
151
  post_install_message:
161
152
  rdoc_options: []
162
153
  require_paths:
163
154
  - lib
164
155
  required_ruby_version: !ruby/object:Gem::Requirement
165
- none: false
166
156
  requirements:
167
- - - ! '>='
157
+ - - '>='
168
158
  - !ruby/object:Gem::Version
169
159
  version: '0'
170
- segments:
171
- - 0
172
- hash: -2883142524196216213
173
160
  required_rubygems_version: !ruby/object:Gem::Requirement
174
- none: false
175
161
  requirements:
176
- - - ! '>='
162
+ - - '>='
177
163
  - !ruby/object:Gem::Version
178
164
  version: '0'
179
- segments:
180
- - 0
181
- hash: -2883142524196216213
182
165
  requirements: []
183
166
  rubyforge_project:
184
- rubygems_version: 1.8.25
167
+ rubygems_version: 2.0.6
185
168
  signing_key:
186
- specification_version: 3
169
+ specification_version: 4
187
170
  summary: Reliable beanstalk background job processing made easy for Ruby and Sinatra
188
171
  test_files:
189
172
  - test/async_proxy_test.rb
@@ -205,3 +188,4 @@ test_files:
205
188
  - test/workers/forking_worker_test.rb
206
189
  - test/workers/simple_worker_test.rb
207
190
  - test/workers/threads_on_fork_worker_test.rb
191
+ has_rdoc: