This document describes Celery 2.4. For development docs, go here.

celery.events.state

celery.events.state

This module implements a datastructure used to keep track of the state of a cluster of workers and the tasks it is working on (by consuming events).

For every event consumed the state is updated, so the state represents the state of the cluster at the time of the last event.

Snapshots (celery.events.snapshot) can be used to take “pictures” of this state at regular intervals to e.g. store that in a database.

copyright:
  1. 2009 - 2011 by Ask Solem.
license:

BSD, see LICENSE for more details.

class celery.events.state.Element

Base class for worker state elements.

celery.events.state.HEARTBEAT_EXPIRE = 150

Hartbeat expiry time in seconds. The worker will be considered offline if no heartbeat is received within this time. Default is 2:30 minutes.

class celery.events.state.State(callback=None, max_workers_in_memory=5000, max_tasks_in_memory=10000)

Records clusters state.

alive_workers()

Returns a list of (seemingly) alive workers.

clear(ready=True)
clear_tasks(ready=True)
event(event)
event_count = 0
freeze_while(fun, *args, **kwargs)
get_or_create_task(uuid)

Get or create task by uuid.

get_or_create_worker(hostname, **kwargs)

Get or create worker by hostname.

itertasks(limit=None)
task_count = 0
task_event(type, fields)

Process task event.

task_types()

Returns a list of all seen task types.

tasks_by_timestamp(limit=None)

Get tasks by timestamp.

Returns a list of (uuid, task) tuples.

tasks_by_type(name, limit=None)

Get all tasks by type.

Returns a list of (uuid, task) tuples.

tasks_by_worker(hostname, limit=None)

Get all tasks by worker.

Returns a list of (uuid, task) tuples.

worker_event(type, fields)

Process worker event.

class celery.events.state.Task(**fields)

Task State.

info(fields=None, extra=[])

Information about this task suitable for on-screen display.

merge(state, timestamp, fields)

Merge with out of order event.

merge_rules = {'RECEIVED': ('name', 'args', 'kwargs', 'retries', 'eta', 'expires')}

How to merge out of order events. Disorder is detected by logical ordering (e.g. task-received must have happened before a task-failed event).

A merge rule consists of a state and a list of fields to keep from that state. (RECEIVED, ("name", "args"), means the name and args fields are always taken from the RECEIVED state, and any values for these fields received before or after is simply ignored.

on_failed(timestamp=None, **fields)

Callback for the task-failed event.

on_received(timestamp=None, **fields)

Callback for the task-received event.

on_retried(timestamp=None, **fields)

Callback for the task-retried event.

on_revoked(timestamp=None, **fields)

Callback for the task-revoked event.

on_sent(timestamp=None, **fields)

Callback for the task-sent event.

on_started(timestamp=None, **fields)

Callback for the task-started event.

on_succeeded(timestamp=None, **fields)

Callback for the task-succeeded event.

on_unknown_event(type, timestamp=None, **fields)
ready
update(state, timestamp, fields)

Update state from new event.

Parameters:
  • state – State from event.
  • timestamp – Timestamp from event.
  • fields – Event data.
class celery.events.state.Worker(**fields)

Worker State.

alive
heartbeat_max = 4
on_heartbeat(timestamp=None, **kwargs)

Callback for the worker-heartbeat event.

on_offline(**kwargs)

Callback for the worker-offline event.

on_online(timestamp=None, **kwargs)

Callback for the worker-online event.