Skip to content

Callbacks

Wayfarer supports a number of callbacks in addition to ActiveJob callbacks.

Available callbacks

  • before_fetch
  • around_fetch
  • after_fetch
  • before_action
  • around_action
  • after_action
  • after_batch

after_batch

You can register after_batch callbacks that run when there are no more tasks to process in a batch. Wayfarer instruments job execution and in- or decrements an integer counter in Redis on certain events. When the counter reaches zero, the current job's after_batch callbacks run.

after_batch callbacks fire at most once per batch.

Conditional callbacks

You can make callbacks conditional with the :if and :unless keywords, for example to run a callback for some route action only:

class DummyJob < ActiveJob::Base
  include Wayfarer::Base

  route.host "example.com", to: :example
  route.to :fallback

  before_action unless: -> { action == :fallback } do
    # ...
  end

  # ...
end

You can also pass a symbol instead of a block to call an instance method.