Celery.Worker.Control (celery v0.1.3)

Copy Markdown View Source

Remote control and inspection commands for Celery workers over Kombu.Pidbox (ported from celery.worker.control and celery.app.control).

Supports standard Celery control/inspect methods:

  • ping -> %{"ok" => "pong"}
  • registered -> list of registered task names (with optional [metadata=...] when taskinfoitems is requested)
  • active -> list of currently executing task request info maps
  • reserved -> list of prefetched/reserved task request info maps
  • scheduled -> list of ETA-scheduled task maps
  • revoked -> list of revoked task IDs
  • active_queues -> list of queue dictionaries consumed by the worker
  • conf -> worker configuration dictionary
  • stats -> worker statistics dictionary
  • report -> worker software/environment report
  • enable_events / disable_events -> toggles event emission
  • heartbeat -> triggers an immediate worker heartbeat
  • revoke -> revokes one or more task_ids
  • shutdown -> stops the worker gracefully

Summary

Functions

Broadcasts a control/inspect command to workers via Kombu.Pidbox.

Builds the handler map used by a Celery.Worker's Kombu.Pidbox.Node to respond to remote control and inspect requests from Python or Elixir Celery clients.

Formats a worker's %Kombu.Queue{} list into the dictionary list expected by Flower and inspect().active_queues().

Formats registered tasks for inspect.registered, supporting taskinfoitems (such as ["metadata"] used by OpenRelik's inspect().registered("metadata")).

Broadcasts an inspect command and collects replies from workers via Kombu.Pidbox.

Creates a %Kombu.Pidbox.Mailbox{} (type: "fanout") for the given %Celery{} or %Celery.Config{}.

Pings active workers via Kombu.Pidbox and collects replies.

Broadcasts a revoke command for task_id (or a list of task IDs) to workers.

Functions

broadcast(app_or_config, command, arguments \\ %{}, opts \\ [])

@spec broadcast(Celery.t() | Celery.Config.t(), String.t(), map(), keyword()) ::
  :ok | list() | {:ok, list()} | {:error, term()}

Broadcasts a control/inspect command to workers via Kombu.Pidbox.

build_handlers(worker_pid, app)

@spec build_handlers(pid(), Celery.t()) :: %{
  required(String.t()) => (term(), map() -> term())
}

Builds the handler map used by a Celery.Worker's Kombu.Pidbox.Node to respond to remote control and inspect requests from Python or Elixir Celery clients.

format_active_queues(queues)

@spec format_active_queues([Kombu.Queue.t()]) :: [map()]

Formats a worker's %Kombu.Queue{} list into the dictionary list expected by Flower and inspect().active_queues().

format_registered_tasks(app, args \\ %{})

@spec format_registered_tasks(Celery.t(), map()) :: [String.t()]

Formats registered tasks for inspect.registered, supporting taskinfoitems (such as ["metadata"] used by OpenRelik's inspect().registered("metadata")).

inspect_call(app_or_config, command, arguments \\ %{}, opts \\ [])

@spec inspect_call(Celery.t() | Celery.Config.t(), String.t(), map(), keyword()) :: [
  map()
]

Broadcasts an inspect command and collects replies from workers via Kombu.Pidbox.

mailbox(app_or_config)

@spec mailbox(Celery.t() | Celery.Config.t()) :: Kombu.Pidbox.Mailbox.t()

Creates a %Kombu.Pidbox.Mailbox{} (type: "fanout") for the given %Celery{} or %Celery.Config{}.

ping(app_or_config, opts \\ [])

@spec ping(Celery.t() | Celery.Config.t(), keyword()) :: [map()]

Pings active workers via Kombu.Pidbox and collects replies.

revoke(app_or_config, task_ids, opts \\ [])

@spec revoke(Celery.t() | Celery.Config.t(), String.t() | [String.t()], keyword()) ::
  :ok | list() | {:ok, list()} | {:error, term()}

Broadcasts a revoke command for task_id (or a list of task IDs) to workers.