Module: ActiveJob::Callbacks::ClassMethods
- Defined in:
- lib/active_job/callbacks.rb
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 before and after the job is enqueued.
-
#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.
Instance Method Details
#after_enqueue(*filters, &blk) ⇒ Object
Defines a callback that will get called right after the job is enqueued.
class VideoProcessJob < ActiveJob::Base
queue_as :default
after_enqueue do |job|
$statsd.increment "enqueue-video-job.success"
end
def perform(video_id)
Video.find(video_id).process
end
end
118 119 120 |
# File 'lib/active_job/callbacks.rb', line 118 def after_enqueue(*filters, &blk) set_callback(:enqueue, :after, *filters, &blk) end |
#after_perform(*filters, &blk) ⇒ Object
Defines a callback that will get called right after the job’s perform method has finished.
class VideoProcessJob < ActiveJob::Base
queue_as :default
after_perform do |job|
UserMailer.notify_video_processed(job.arguments.first)
end
def perform(video_id)
Video.find(video_id).process
end
end
60 61 62 |
# File 'lib/active_job/callbacks.rb', line 60 def after_perform(*filters, &blk) set_callback(:perform, :after, *filters, &blk) end |
#around_enqueue(*filters, &blk) ⇒ Object
Defines a callback that will get called before and after the job is enqueued.
class VideoProcessJob < ActiveJob::Base
queue_as :default
around_enqueue do |job, block|
$statsd.time "video-job.process" do
block.call
end
end
def perform(video_id)
Video.find(video_id).process
end
end
139 140 141 |
# File 'lib/active_job/callbacks.rb', line 139 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
80 81 82 |
# File 'lib/active_job/callbacks.rb', line 80 def around_perform(*filters, &blk) set_callback(:perform, :around, *filters, &blk) end |
#before_enqueue(*filters, &blk) ⇒ Object
Defines a callback that will get called right before the job is enqueued.
class VideoProcessJob < ActiveJob::Base
queue_as :default
before_enqueue do |job|
$statsd.increment "enqueue-video-job.try"
end
def perform(video_id)
Video.find(video_id).process
end
end
99 100 101 |
# File 'lib/active_job/callbacks.rb', line 99 def before_enqueue(*filters, &blk) set_callback(:enqueue, :before, *filters, &blk) end |
#before_perform(*filters, &blk) ⇒ Object
Defines a callback that will get called right before the job’s perform method is executed.
class VideoProcessJob < ActiveJob::Base
queue_as :default
before_perform do |job|
UserMailer.notify_video_started_processing(job.arguments.first)
end
def perform(video_id)
Video.find(video_id).process
end
end
41 42 43 |
# File 'lib/active_job/callbacks.rb', line 41 def before_perform(*filters, &blk) set_callback(:perform, :before, *filters, &blk) end |