app.control

Worker Remote Control Client.

Client for worker remote control commands. Server implementation is in celery.worker.control.

Module Contents

Classes

Inspect(self,destination=None,timeout=1.0,callback=None,connection=None,app=None,limit=None) API for app.control.inspect.
Control(self,app=None) Worker remote control client.

Functions

flatten_reply(reply) Flatten node replies.
_after_fork_cleanup_control(control)
flatten_reply(reply)

Flatten node replies.

Convert from a list of replies in this format:

[{'a@example.com': reply},
 {'b@example.com': reply}]

into this format:

{'a@example.com': reply,
 'b@example.com': reply}
_after_fork_cleanup_control(control)
class Inspect(destination=None, timeout=1.0, callback=None, connection=None, app=None, limit=None)

API for app.control.inspect.

__init__(destination=None, timeout=1.0, callback=None, connection=None, app=None, limit=None)
_prepare(reply)
_request(command, **kwargs)
report()
clock()
active(safe=None)
scheduled(safe=None)
reserved(safe=None)
stats()
revoked()
registered(*taskinfoitems)
ping(destination=None)
active_queues()
query_task(*ids)
conf(with_defaults=False)
hello(from_node, revoked=None)
memsample()
memdump(samples=10)
objgraph(type="Request", n=200, max_depth=10)
class Control(app=None)

Worker remote control client.

__init__(app=None)
_after_fork()
inspect()
purge(connection=None)

Discard all waiting tasks.

This will ignore all tasks waiting for execution, and they will be deleted from the messaging server.

Arguments:
connection (kombu.Connection): Optional specific connection
instance to use. If not provided a connection will be acquired from the connection pool.
Returns:
int: the number of tasks discarded.
election(id, topic, action=None, connection=None)
revoke(task_id, destination=None, terminate=False, signal=TERM_SIGNAME, **kwargs)

Tell all (or specific) workers to revoke a task by id.

If a task is revoked, the workers will ignore the task and not execute it after all.

Arguments:

task_id (str): Id of the task to revoke. terminate (bool): Also terminate the process currently working

on the task (if any).
signal (str): Name of signal to send to process if terminate.
Default is TERM.
See Also:
broadcast() for supported keyword arguments.
terminate(task_id, destination=None, signal=TERM_SIGNAME, **kwargs)

Tell all (or specific) workers to terminate a task by id.

See Also:
This is just a shortcut to revoke() with the terminate argument enabled.
ping(destination=None, timeout=1.0, **kwargs)

Ping all (or specific) workers.

Returns:
List[Dict]: List of {'hostname': reply} dictionaries.
See Also:
broadcast() for supported keyword arguments.
rate_limit(task_name, rate_limit, destination=None, **kwargs)

Tell workers to set a new rate limit for task by type.

Arguments:

task_name (str): Name of task to change rate limit for. rate_limit (int, str): The rate limit as tasks per second,

or a rate limit string (‘100/m’, etc. see celery.task.base.Task.rate_limit for more information).
See Also:
broadcast() for supported keyword arguments.
add_consumer(queue, exchange=None, exchange_type="direct", routing_key=None, options=None, destination=None, **kwargs)

Tell all (or specific) workers to start consuming from a new queue.

Only the queue name is required as if only the queue is specified then the exchange/routing key will be set to the same name ( like automatic queues do).

Note:
This command does not respect the default queue/exchange options in the configuration.
Arguments:

queue (str): Name of queue to start consuming from. exchange (str): Optional name of exchange. exchange_type (str): Type of exchange (defaults to ‘direct’)

command to, when empty broadcast to all workers.

routing_key (str): Optional routing key. options (Dict): Additional options as supported

by kombu.entitiy.Queue.from_dict().
See Also:
broadcast() for supported keyword arguments.
cancel_consumer(queue, destination=None, **kwargs)

Tell all (or specific) workers to stop consuming from queue.

See Also:
Supports the same arguments as broadcast().
time_limit(task_name, soft=None, hard=None, destination=None, **kwargs)

Tell workers to set time limits for a task by type.

Arguments:
task_name (str): Name of task to change time limits for. soft (float): New soft time limit (in seconds). hard (float): New hard time limit (in seconds). **kwargs (Any): arguments passed on to broadcast().
enable_events(destination=None, **kwargs)

Tell all (or specific) workers to enable events.

See Also:
Supports the same arguments as broadcast().
disable_events(destination=None, **kwargs)

Tell all (or specific) workers to disable events.

See Also:
Supports the same arguments as broadcast().
pool_grow(n=1, destination=None, **kwargs)

Tell all (or specific) workers to grow the pool by n.

See Also:
Supports the same arguments as broadcast().
pool_shrink(n=1, destination=None, **kwargs)

Tell all (or specific) workers to shrink the pool by n.

See Also:
Supports the same arguments as broadcast().
autoscale(max, min, destination=None, **kwargs)

Change worker(s) autoscale setting.

See Also:
Supports the same arguments as broadcast().
shutdown(destination=None, **kwargs)

Shutdown worker(s).

See Also:
Supports the same arguments as broadcast()
pool_restart(modules=None, reload=False, reloader=None, destination=None, **kwargs)

Restart the execution pools of all or specific workers.

Keyword Arguments:

modules (Sequence[str]): List of modules to reload. reload (bool): Flag to enable module reloading. Default is False. reloader (Any): Function to reload a module. destination (Sequence[str]): List of worker names to send this

command to.
See Also:
Supports the same arguments as broadcast()
heartbeat(destination=None, **kwargs)

Tell worker(s) to send a heartbeat immediately.

See Also:
Supports the same arguments as broadcast()
broadcast(command, arguments=None, destination=None, connection=None, reply=False, timeout=1.0, limit=None, callback=None, channel=None, **extra_kwargs)

Broadcast a control command to the celery workers.

Arguments:

command (str): Name of command to send. arguments (Dict): Keyword arguments for the command. destination (List): If set, a list of the hosts to send the

command to, when empty broadcast to all workers.
connection (kombu.Connection): Custom broker connection to use,
if not set, a connection will be acquired from the pool.

reply (bool): Wait for and return the reply. timeout (float): Timeout in seconds to wait for the reply. limit (int): Limit number of replies. callback (Callable): Callback called immediately for

each reply received.