Celery.Events (celery v0.1.2)

Copy Markdown View Source

Celery event creation, formatting, and publishing to the celeryev topic exchange (ported from celery.events and celery.events.dispatcher).

Emits worker (worker-online, worker-heartbeat, worker-offline) and task lifecycle events (task-received, task-started, task-succeeded, task-failed, task-retried, task-revoked) compatible with Flower, celery.events.EventReceiver, and OpenRelik Mediator.

Summary

Functions

Builds a Celery event dictionary matching celery.events.Event.

Returns the celeryev exchange (durable: true). Matches Python Celery's celery.events.event.get_exchange/2, which switches the exchange type from "topic" to "fanout" when Redis is used as the transport.

Returns the OS PID as an integer.

Publishes a Celery event to the celeryev exchange on channel_or_conn.

Default software identity metadata included in worker-online, worker-heartbeat, and worker-offline events.

Formats an Elixir value as a Python literal string (repr()), suitable for Python's ast.literal_eval/1 (e.g. inspect().registered("metadata") in OpenRelik and args/kwargs/result in Flower).

Functions

build_event(type, hostname, fields \\ %{}, opts \\ [])

@spec build_event(String.t(), String.t(), map(), keyword()) :: {String.t(), map()}

Builds a Celery event dictionary matching celery.events.Event.

Converts "worker-online" into routing key "worker.online", attaches standard metadata (hostname, timestamp, utcoffset, pid, clock, local_received), and merges fields.

exchange(channel_or_conn \\ nil)

@spec exchange(term()) :: Kombu.Exchange.t()

Returns the celeryev exchange (durable: true). Matches Python Celery's celery.events.event.get_exchange/2, which switches the exchange type from "topic" to "fanout" when Redis is used as the transport.

os_pid()

@spec os_pid() :: pos_integer()

Returns the OS PID as an integer.

publish(channel_or_conn, type, hostname, fields \\ %{}, opts \\ [])

@spec publish(term(), String.t(), String.t(), map(), keyword()) :: :ok

Publishes a Celery event to the celeryev exchange on channel_or_conn.

sw_info()

@spec sw_info() :: map()

Default software identity metadata included in worker-online, worker-heartbeat, and worker-offline events.

to_python_repr(n)

@spec to_python_repr(term()) :: String.t()

Formats an Elixir value as a Python literal string (repr()), suitable for Python's ast.literal_eval/1 (e.g. inspect().registered("metadata") in OpenRelik and args/kwargs/result in Flower).