onyx-resque-retry 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -129,7 +129,7 @@ module Resque
129
129
 
130
130
  # call user retry criteria check blocks.
131
131
  retry_criteria_checks.each do |criteria_check|
132
- should_retry ||= !!criteria_check.call(exception, *args)
132
+ should_retry ||= !!instance_exec(exception, *args, &criteria_check)
133
133
  end
134
134
 
135
135
  should_retry
data/lib/resque-retry.rb CHANGED
@@ -4,3 +4,17 @@ require 'resque_scheduler'
4
4
  require 'resque/plugins/retry'
5
5
  require 'resque/plugins/exponential_backoff'
6
6
  require 'resque/failure/multiple_with_retry_suppression'
7
+
8
+ class Object
9
+ def instance_exec(*args, &block)
10
+ mname = "__instance_exec_#{Thread.current.object_id.abs}"
11
+ class << self; self end.class_eval{ define_method(mname, &block) }
12
+ begin
13
+ puts "instance_exec args = #{args.inspect}"
14
+ ret = send(mname, *args)
15
+ ensure
16
+ class << self; self end.class_eval{ undef_method(mname) } rescue nil
17
+ end
18
+ ret
19
+ end
20
+ end
@@ -30,4 +30,16 @@ class RetryInheritingChecksTest < Test::Unit::TestCase
30
30
  assert_equal 1, klass.retry_criteria_checks.size
31
31
  assert_equal 'test', klass.test_value
32
32
  end
33
+
34
+ def test_retry_criteria_check_should_be_evaluated_under_child_context
35
+ Resque.enqueue(InheritedJob, 'arg')
36
+
37
+ 10.times do
38
+ perform_next_job(@worker)
39
+ end
40
+
41
+ assert_equal 0, BaseJob.retry_attempt, "BaseJob retry attempts"
42
+ assert_equal 0, InheritedJob.retry_attempt, "InheritedJob retry attempts"
43
+ assert_equal 5, InheritedRetryJob.retry_attempt, "InheritedRetryJob retry attempts"
44
+ end
33
45
  end
data/test/test_helper.rb CHANGED
@@ -6,6 +6,7 @@ require 'test/unit'
6
6
  require 'rubygems'
7
7
  require 'turn'
8
8
  require 'simplecov'
9
+ require 'mocha'
9
10
 
10
11
  SimpleCov.start do
11
12
  add_filter "/test/"
@@ -28,11 +29,7 @@ end
28
29
  at_exit do
29
30
  next if $!
30
31
 
31
- if defined?(MiniTest)
32
- exit_code = MiniTest::Unit.new.run(ARGV)
33
- else
34
- exit_code = Test::Unit::AutoRunner.run
35
- end
32
+ exit_code = Test::Unit::AutoRunner.run
36
33
 
37
34
  pid = `ps -e -o pid,command | grep [r]edis-test`.split(" ")[0]
38
35
  puts "Killing test redis server..."
data/test/test_jobs.rb CHANGED
@@ -147,6 +147,58 @@ module RetryModuleDefaultsJob
147
147
  end
148
148
  end
149
149
 
150
+ class AsyncJob
151
+ extend Resque::Plugins::Retry
152
+
153
+ class << self
154
+ def perform(*opts)
155
+ process
156
+ end
157
+
158
+ def process
159
+ raise "Shouldn't be called"
160
+ end
161
+ end
162
+ end
163
+
164
+ class BaseJob < AsyncJob
165
+ @retry_limit = 0
166
+ @auto_retry_limit = 5
167
+ @retry_exceptions = []
168
+
169
+ retry_criteria_check do |exception, *args|
170
+ keep_trying?
171
+ end
172
+
173
+ class << self
174
+ def keep_trying?
175
+ retry_attempt < @auto_retry_limit
176
+ end
177
+
178
+ def inherited(subclass)
179
+ super
180
+ %w(@retry_exceptions @retry_delay @retry_limit @auto_retry_limit).each do |variable|
181
+ value = BaseJob.instance_variable_get(variable)
182
+ value = value.dup rescue value
183
+ subclass.instance_variable_set(variable, value)
184
+ end
185
+ end
186
+
187
+ def process
188
+ raise "Got called #{Time.now}"
189
+ end
190
+ end
191
+ end
192
+
193
+ class InheritedRetryJob < BaseJob
194
+ @queue = :testing
195
+ end
196
+
197
+ class InheritedJob < BaseJob
198
+ @queue = :testing
199
+ @retry_job_class = InheritedRetryJob
200
+ end
201
+
150
202
  module RetryModuleCustomRetryCriteriaCheck
151
203
  extend Resque::Plugins::Retry
152
204
  @queue = :testing
metadata CHANGED
@@ -1,21 +1,22 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onyx-resque-retry
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
- - Onyx Team
13
+ - Luke Antins
14
+ - Ryan Carver
14
15
  autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2011-10-13 00:00:00 -04:00
19
+ date: 2011-10-18 00:00:00 -04:00
19
20
  default_executable:
20
21
  dependencies:
21
22
  - !ruby/object:Gem::Dependency
@@ -135,18 +136,18 @@ files:
135
136
  - Rakefile
136
137
  - README.md
137
138
  - HISTORY.md
138
- - test/retry_test.rb
139
+ - test/redis-test.conf
139
140
  - test/multiple_failure_test.rb
140
141
  - test/retry_inheriting_checks_test.rb
141
- - test/redis-test.conf
142
- - test/retry_criteria_test.rb
143
142
  - test/resque_test.rb
143
+ - test/test_jobs.rb
144
+ - test/retry_criteria_test.rb
145
+ - test/retry_test.rb
144
146
  - test/exponential_backoff_test.rb
145
147
  - test/test_helper.rb
146
- - test/test_jobs.rb
147
- - lib/resque/failure/multiple_with_retry_suppression.rb
148
- - lib/resque/plugins/exponential_backoff.rb
149
148
  - lib/resque/plugins/retry.rb
149
+ - lib/resque/plugins/exponential_backoff.rb
150
+ - lib/resque/failure/multiple_with_retry_suppression.rb
150
151
  - lib/resque-retry.rb
151
152
  - lib/resque-retry/server/views/retry.erb
152
153
  - lib/resque-retry/server/views/retry_timestamp.erb