Exq.Middleware.Server (exq v0.19.0) View Source

Middleware Server is responsible for storing middleware chain that is evaluated when performing particular job.

Middleware chain defaults to Stats, Job and Manager middlewares.

To push new middleware you must create module with common interface. Interface is similar to Plug implementation. It has three functions, every function receives Exq.Middlewares.Pipeline structure and every function must return the same structure, modified or not.

Basically, before_work/1 function may update worker state, while after_processed_work/1 and after_failed_work/1 are for cleanup and notification stuff.

For example, here is a valid middleware module:

defmodule MyMiddleware do
  @behaiour Exq.Middleware.Behaviour

  def before_work(pipeline) do
    # some functionality goes here...
    pipeline
  end

  def after_processed_work(pipeline) do
    # some functionality goes here...
    pipeline
  end

  def after_failed_work(pipeline) do
    # some functionality goes here...
    pipeline
  end
end

To add this module to middleware chain:

Exq.Middleware.Server.push(middleware_server_pid, MyMiddleware)

Link to this section Summary

Functions

Retrieves list of middleware modules.

Returns a specification to start this module under a supervisor.

Callback implementation for GenServer.init/1.

Adds specified middleware module into the end of middleware list.

Returns middleware server name.

Starts middleware server.

Link to this section Functions

Retrieves list of middleware modules.

Returns a specification to start this module under a supervisor.

See Supervisor.

Callback implementation for GenServer.init/1.

Adds specified middleware module into the end of middleware list.

middleware should have Exq.Middleware.Behaviour behaviour.

Returns middleware server name.

Starts middleware server.