instance method around_perform

Ruby on Rails 8.1.2

Since v4.2.9

Available in: v4.2.9 v5.2.8.1 v6.0.6 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

around_perform(*filters, &blk)

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

Parameters

filters rest
blk block
Source
# File activejob/lib/active_job/callbacks.rb, line 102
      def around_perform(*filters, &blk)
        set_callback(:perform, :around, *filters, &blk)
      end

Defined in activejob/lib/active_job/callbacks.rb line 102 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveJob::Callbacks::ClassMethods

Type at least 2 characters to search.

↑↓ navigate · open · esc close