backburner 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,10 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## Version 0.4.3 (July 19 2013)
4
+
5
+ * FIX #44 Additional fix to issue introduced in 0.4.2
6
+ * FIX #45 More graceful shutdown using Kernel.exit and rescuing SystemExit. (Thanks @ryanjohns)
7
+
3
8
  ## Version 0.4.2 (July 3 2013)
4
9
 
5
10
  * FIX #44 Properly retry to connect to beanstalkd when connection fails.
@@ -1,3 +1,3 @@
1
1
  module Backburner
2
- VERSION = "0.4.2"
2
+ VERSION = "0.4.3"
3
3
  end
@@ -27,15 +27,15 @@ module Backburner
27
27
  pri = resolve_priority(opts[:pri] || job_class)
28
28
  delay = [0, opts[:delay].to_i].max
29
29
  ttr = opts[:ttr] || Backburner.configuration.respond_timeout
30
- tube = connection.tubes[expand_tube_name(opts[:queue] || job_class)]
31
30
  res = Backburner::Hooks.invoke_hook_events(job_class, :before_enqueue, *args)
32
31
  return false unless res # stop if hook is false
33
32
  data = { :class => job_class.name, :args => args }
34
- tube.put data.to_json, :pri => pri, :delay => delay, :ttr => ttr
33
+ retryable_command do
34
+ tube = connection.tubes[expand_tube_name(opts[:queue] || job_class)]
35
+ tube.put(data.to_json, :pri => pri, :delay => delay, :ttr => ttr)
36
+ end
35
37
  Backburner::Hooks.invoke_hook_events(job_class, :after_enqueue, *args)
36
38
  return true
37
- rescue Beaneater::NotConnected => e
38
- retry_connection!
39
39
  end
40
40
 
41
41
  # Starts processing jobs with the specified tube_names.
@@ -44,7 +44,11 @@ module Backburner
44
44
  # Backburner::Worker.start(["foo.tube.name"])
45
45
  #
46
46
  def self.start(tube_names=nil)
47
- self.new(tube_names).start
47
+ begin
48
+ self.new(tube_names).start
49
+ rescue SystemExit
50
+ # do nothing
51
+ end
48
52
  end
49
53
 
50
54
  # Returns the worker connection.
@@ -54,23 +58,21 @@ module Backburner
54
58
  @connection ||= Connection.new(Backburner.configuration.beanstalk_url)
55
59
  end
56
60
 
57
- # Retries to make a connection to beanstalkd if that connection failed.
61
+ # Retries the given command specified in the block several times if there is a connection error
62
+ # Used to execute beanstalkd commands in a retryable way
63
+ #
64
+ # @example
65
+ # retryable_command { ... }
58
66
  # @raise [Beaneater::NotConnected] If beanstalk fails to connect multiple times.
59
- def self.retry_connection!(max_tries=5)
60
- retry_count = 0
67
+ #
68
+ def self.retryable_command(max_tries=8, &block)
61
69
  begin
62
- @connection = nil
63
- self.connection
70
+ yield
64
71
  rescue Beaneater::NotConnected => e
65
- if retry_count < max_tries
66
- retry_count += 1
67
- sleep 0.5
68
- retry
69
- else # stop retrying
70
- raise e
71
- end
72
+ retry_connection!(max_tries)
73
+ yield
72
74
  end
73
- end # retry_connection!
75
+ end
74
76
 
75
77
  # List of tube names to be watched and processed
76
78
  attr_accessor :tube_names
@@ -111,7 +113,7 @@ module Backburner
111
113
  # Triggers this worker to shutdown
112
114
  def shutdown
113
115
  log_info 'Worker exiting...'
114
- Kernel.exit!
116
+ Kernel.exit
115
117
  end
116
118
 
117
119
  # Processes tube_names given tube_names array.
@@ -156,6 +158,41 @@ module Backburner
156
158
  handle_error(e, job.name, job.args)
157
159
  end
158
160
 
161
+ # Retries the given command specified in the block several times if there is a connection error
162
+ # Used to execute beanstalkd commands in a retryable way
163
+ #
164
+ # @example
165
+ # retryable_command { ... }
166
+ # @raise [Beaneater::NotConnected] If beanstalk fails to connect multiple times.
167
+ #
168
+ def self.retryable_command(max_tries=8, &block)
169
+ begin
170
+ yield
171
+ rescue Beaneater::NotConnected => e
172
+ retry_connection!(max_tries)
173
+ yield
174
+ end
175
+ end
176
+
177
+ # Retries to make a connection to beanstalkd if that connection failed.
178
+ # @raise [Beaneater::NotConnected] If beanstalk fails to connect multiple times.
179
+ #
180
+ def self.retry_connection!(max_tries=8)
181
+ retry_count = 0
182
+ begin
183
+ @connection = nil
184
+ self.connection.stats
185
+ rescue Beaneater::NotConnected => e
186
+ if retry_count < max_tries
187
+ retry_count += 1
188
+ sleep 1
189
+ retry
190
+ else # stop retrying
191
+ raise e
192
+ end
193
+ end
194
+ end # retry_connection!
195
+
159
196
  protected
160
197
 
161
198
  # Returns a list of all tubes known within the system
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: backburner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-03 00:00:00.000000000 Z
12
+ date: 2013-07-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: beaneater
@@ -169,7 +169,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
169
169
  version: '0'
170
170
  segments:
171
171
  - 0
172
- hash: -4352332376795710100
172
+ hash: -2883142524196216213
173
173
  required_rubygems_version: !ruby/object:Gem::Requirement
174
174
  none: false
175
175
  requirements:
@@ -178,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
178
178
  version: '0'
179
179
  segments:
180
180
  - 0
181
- hash: -4352332376795710100
181
+ hash: -2883142524196216213
182
182
  requirements: []
183
183
  rubyforge_project:
184
184
  rubygems_version: 1.8.25