@@ -106,11 +106,6 @@ def perform
106
106
job_args = args || [ ]
107
107
job_was_performed = false
108
108
109
- before_hooks = Plugin . before_hooks ( job )
110
- around_hooks = Plugin . around_hooks ( job )
111
- after_hooks = Plugin . after_hooks ( job )
112
- failure_hooks = Plugin . failure_hooks ( job )
113
-
114
109
begin
115
110
# Execute before_perform hook. Abort the job gracefully if
116
111
# Resque::DontPerform is raised.
@@ -158,7 +153,7 @@ def perform
158
153
# If an exception occurs during the job execution, look for an
159
154
# on_failure hook then re-raise.
160
155
rescue Object => e
161
- failure_hooks . each { | hook | job . send ( hook , e , * job_args ) }
156
+ run_failure_hooks ( e )
162
157
raise e
163
158
end
164
159
end
@@ -176,6 +171,7 @@ def args
176
171
# Given an exception object, hands off the needed parameters to
177
172
# the Failure module.
178
173
def fail ( exception )
174
+ run_failure_hooks ( exception )
179
175
Failure . create \
180
176
:payload => payload ,
181
177
:exception => exception ,
@@ -201,5 +197,27 @@ def ==(other)
201
197
payload_class == other . payload_class &&
202
198
args == other . args
203
199
end
200
+
201
+ def before_hooks
202
+ @before_hooks ||= Plugin . before_hooks ( payload_class )
203
+ end
204
+
205
+ def around_hooks
206
+ @around_hooks ||= Plugin . around_hooks ( payload_class )
207
+ end
208
+
209
+ def after_hooks
210
+ @after_hooks ||= Plugin . after_hooks ( payload_class )
211
+ end
212
+
213
+ def failure_hooks
214
+ @failure_hooks ||= Plugin . failure_hooks ( payload_class )
215
+ end
216
+
217
+ def run_failure_hooks ( exception )
218
+ job_args = args || [ ]
219
+ failure_hooks . each { |hook | payload_class . send ( hook , exception , *job_args ) }
220
+ end
221
+
204
222
end
205
223
end
0 commit comments