exq v0.8.5 Exq.Middleware.Server

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)

Summary

Functions

Retrieves list of middleware modules

Adds specified middleware module into the end of middleware list. middleware should have Exq.Middleware.Behaviour behaviour

Returns middleware server name

Starts middleware server

Functions

all(pid)

Retrieves list of middleware modules

push(pid, middleware)

Adds specified middleware module into the end of middleware list. middleware should have Exq.Middleware.Behaviour behaviour

server_name(name)

Returns middleware server name

start_link(opts \\ [])

Starts middleware server