Module: ActiveJob::Callbacks::ClassMethods
- Defined in:
- activejob/lib/active_job/callbacks.rb
Overview
These methods will be included into any Active Job object, adding callbacks for perform
and enqueue
methods.
Instance Method Summary collapse
-
#after_enqueue(*filters, &blk) ⇒ Object
Defines a callback that will get called right after the job is enqueued.
-
#after_perform(*filters, &blk) ⇒ Object
Defines a callback that will get called right after the job’s perform method has finished.
-
#around_enqueue(*filters, &blk) ⇒ Object
Defines a callback that will get called around the enqueuing of the job.
-
#around_perform(*filters, &blk) ⇒ Object
Defines a callback that will get called around the job’s perform method.
-
#before_enqueue(*filters, &blk) ⇒ Object
Defines a callback that will get called right before the job is enqueued.
-
#before_perform(*filters, &blk) ⇒ Object
Defines a callback that will get called right before the job’s perform method is executed.
- #inherited(klass) ⇒ Object
Instance Method Details
#after_enqueue(*filters, &blk) ⇒ Object
142 143 144 |
# File 'activejob/lib/active_job/callbacks.rb', line 142 def after_enqueue(*filters, &blk) set_callback(:enqueue, :after, *filters, &blk) end |
#after_perform(*filters, &blk) ⇒ Object
84 85 86 |
# File 'activejob/lib/active_job/callbacks.rb', line 84 def after_perform(*filters, &blk) set_callback(:perform, :after, *filters, &blk) end |
#around_enqueue(*filters, &blk) ⇒ Object
163 164 165 |
# File 'activejob/lib/active_job/callbacks.rb', line 163 def around_enqueue(*filters, &blk) set_callback(:enqueue, :around, *filters, &blk) end |
#around_perform(*filters, &blk) ⇒ Object
Defines a callback that will get called around the job’s perform method.
class VideoProcessJob < ActiveJob::Base
queue_as :default
around_perform do |job, block|
UserMailer.notify_video_started_processing(job.arguments.first)
block.call
UserMailer.notify_video_processed(job.arguments.first)
end
def perform(video_id)
Video.find(video_id).process
end
end
104 105 106 |
# File 'activejob/lib/active_job/callbacks.rb', line 104 def around_perform(*filters, &blk) set_callback(:perform, :around, *filters, &blk) end |
#before_enqueue(*filters, &blk) ⇒ Object
123 124 125 |
# File 'activejob/lib/active_job/callbacks.rb', line 123 def before_enqueue(*filters, &blk) set_callback(:enqueue, :before, *filters, &blk) end |
#before_perform(*filters, &blk) ⇒ Object
65 66 67 |
# File 'activejob/lib/active_job/callbacks.rb', line 65 def before_perform(*filters, &blk) set_callback(:perform, :before, *filters, &blk) end |
#inherited(klass) ⇒ Object
44 45 46 47 48 |
# File 'activejob/lib/active_job/callbacks.rb', line 44 def inherited(klass) klass.get_callbacks(:enqueue).config[:skip_after_callbacks_if_terminated] = skip_after_callbacks_if_terminated klass.get_callbacks(:perform).config[:skip_after_callbacks_if_terminated] = skip_after_callbacks_if_terminated super end |