Module: ActiveJob::Callbacks::ClassMethods
- Defined in:
- lib/solargraph/rails/annotations/active_job.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) ⇒ void
Defines a callback that will get called right after the job is enqueued.
-
#after_perform(*filters, &blk) ⇒ void
Defines a callback that will get called right after the job’s perform method has finished.
-
#around_enqueue(*filters, &blk) ⇒ void
Defines a callback that will get called around the enqueuing of the job.
-
#around_perform(*filters, &blk) ⇒ void
Defines a callback that will get called around the job’s perform method.
-
#before_enqueue(*filters, &blk) ⇒ void
Defines a callback that will get called right before the job is enqueued.
-
#before_perform(*filters, &blk) ⇒ void
Defines a callback that will get called right before the job’s perform method is executed.
Instance Method Details
#after_enqueue(*filters, &blk) ⇒ void
This method returns an undefined value.
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
114 |
# File 'lib/solargraph/rails/annotations/active_job.rb', line 114 def after_enqueue(*filters, &blk); end |
#after_perform(*filters, &blk) ⇒ void
This method returns an undefined value.
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
43 |
# File 'lib/solargraph/rails/annotations/active_job.rb', line 43 def after_perform(*filters, &blk); end |
#around_enqueue(*filters, &blk) ⇒ void
This method returns an undefined value.
Defines a callback that will get called around the enqueuing of the job.
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
135 |
# File 'lib/solargraph/rails/annotations/active_job.rb', line 135 def around_enqueue(*filters, &blk); end |
#around_perform(*filters, &blk) ⇒ void
This method returns an undefined value.
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
You can access the return value of the job only if the execution wasn’t halted.
class VideoProcessJob < ActiveJob::Base
around_perform do |job, block|
value = block.call
puts value # => "Hello World!"
end
def perform
"Hello World!"
end
end
76 |
# File 'lib/solargraph/rails/annotations/active_job.rb', line 76 def around_perform(*filters, &blk); end |
#before_enqueue(*filters, &blk) ⇒ void
This method returns an undefined value.
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
95 |
# File 'lib/solargraph/rails/annotations/active_job.rb', line 95 def before_enqueue(*filters, &blk); end |
#before_perform(*filters, &blk) ⇒ void
This method returns an undefined value.
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
24 |
# File 'lib/solargraph/rails/annotations/active_job.rb', line 24 def before_perform(*filters, &blk); end |