Celery.Worker (celery v0.1.0)

Copy Markdown View Source

Celery Worker / Consumer OTP GenServer (ported from celery.worker).

Consumes Celery task messages from Redis (or memory:// in tests) via Kombu, decodes Protocol v1 and v2 task messages, schedules ETA/countdown tasks, enforces concurrency limits, executes tasks through Celery.Tracer, stores results in Celery.Backend.Redis, and optionally listens for Kombu.Pidbox control commands.

Starting a Worker

celery = Celery.new(
  broker: "redis://localhost:6379/0",
  backend: "redis://localhost:6379/0",
  include: ["src.tasks"]
)

{:ok, worker} = Celery.Worker.start_link(app: celery, concurrency: 4)

Summary

Functions

Returns the list of currently executing task requests (inspect.active).

Returns a specification to start this module under a supervisor.

Returns the list of prefetched/reserved task requests (inspect.reserved).

Revokes one or more task IDs on this worker.

Returns the list of revoked task IDs on this worker (inspect.revoked).

Returns the list of ETA-scheduled task requests (inspect.scheduled).

Starts a Celery.Worker linked to the calling process.

Returns worker statistics (inspect.stats).

Stops a running Celery.Worker gracefully.

Types

t()

@type t() :: pid()

Functions

active(worker)

@spec active(GenServer.server()) :: [map()]

Returns the list of currently executing task requests (inspect.active).

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

reserved(worker)

@spec reserved(GenServer.server()) :: [map()]

Returns the list of prefetched/reserved task requests (inspect.reserved).

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

@spec revoke(GenServer.server(), String.t() | [String.t()], keyword()) :: :ok

Revokes one or more task IDs on this worker.

revoked(worker)

@spec revoked(GenServer.server()) :: [String.t()]

Returns the list of revoked task IDs on this worker (inspect.revoked).

scheduled(worker)

@spec scheduled(GenServer.server()) :: [map()]

Returns the list of ETA-scheduled task requests (inspect.scheduled).

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

Starts a Celery.Worker linked to the calling process.

Options

  • :app - %Celery{} instance (required, or built from remaining options)
  • :queues - list of queue names or %Kombu.Queue{} structs to consume from
  • :hostname - worker node hostname (default "celery@<host>")
  • :concurrency - maximum number of concurrent task processes (default app.config.worker_concurrency)
  • :poll_interval - poll interval in milliseconds (default 25)
  • :enable_remote_control - whether to start a Kombu.Pidbox.Node listener (default false)
  • :notify - optional PID to receive {:celery_task_done, task_id, outcome} events
  • :name - optional GenServer registration name

stats(worker)

@spec stats(GenServer.server()) :: map()

Returns worker statistics (inspect.stats).

stop(worker, timeout \\ 5000)

@spec stop(GenServer.server(), timeout()) :: :ok

Stops a running Celery.Worker gracefully.