Class: PerformMiddlewareInterface

Inherits:
Object
  • Object
show all
Defined in:
lib/rage/configuration.rb

Overview

Note:

This class does not exist at runtime and is used for documentation purposes only. Do not inherit your middleware classes from it.

Instance Method Summary collapse

Instance Method Details

#call(task_class:, task:, phase:, args:, kwargs:, context:) ⇒ Object

Called whenever a deferred task is performed.

The middleware is expected to call yield to pass control to the next middleware in the stack. If the middleware does not call yield, the task will not be performed.

Rage automatically detects which parameters your middleware’s #call method accepts, and only passes those parameters. You can omit any of the described parameters in your implementation.

Examples:

class DecryptArgumentsMiddleware
  def call(args:, kwargs:)
    args.map! { |arg| MyEncryptionSDK.decrypt(arg) }
    kwargs.transform_values! { |value| MyEncryptionSDK.decrypt(value) }

    yield

  rescue
    # Re-encrypt the arguments in case of an error
    args.map! { |arg| MyEncryptionSDK.encrypt(arg) }
    kwargs.transform_values! { |value| MyEncryptionSDK.encrypt(value) }
    raise
  end
end

Parameters:

  • task_class (Class)

    the deferred task class

  • task (Rage::Deferred::Task)

    the deferred task instance

  • phase (:perform)

    the middleware phase. Useful for middlewares that are shared between enqueue and perform phases

  • args (Array)

    the positional arguments passed to the task

  • kwargs (Hash)

    the keyword arguments passed to the task

  • context (Hash)

    the context is serialized together with the task and allows passing data between middlewares without exposing it to the task itself



30
31
# File 'lib/rage/configuration.rb', line 30

def call(task_class:, task:, phase:, args:, kwargs:, context:)
end