@@ -106,11 +106,6 @@ def perform
106106 job_args = args || [ ]
107107 job_was_performed = false
108108
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-
114109 begin
115110 # Execute before_perform hook. Abort the job gracefully if
116111 # Resque::DontPerform is raised.
@@ -158,7 +153,7 @@ def perform
158153 # If an exception occurs during the job execution, look for an
159154 # on_failure hook then re-raise.
160155 rescue Object => e
161- failure_hooks . each { | hook | job . send ( hook , e , * job_args ) }
156+ run_failure_hooks ( e )
162157 raise e
163158 end
164159 end
@@ -176,6 +171,7 @@ def args
176171 # Given an exception object, hands off the needed parameters to
177172 # the Failure module.
178173 def fail ( exception )
174+ run_failure_hooks ( exception )
179175 Failure . create \
180176 :payload => payload ,
181177 :exception => exception ,
@@ -201,5 +197,27 @@ def ==(other)
201197 payload_class == other . payload_class &&
202198 args == other . args
203199 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+
204222 end
205223end
0 commit comments