|
@@ -76,24 +76,9 @@ class Inspect(object):
|
|
return self._request("dump_tasks")
|
|
return self._request("dump_tasks")
|
|
registered_tasks = registered
|
|
registered_tasks = registered
|
|
|
|
|
|
- def enable_events(self):
|
|
|
|
- return self._request("enable_events")
|
|
|
|
-
|
|
|
|
- def disable_events(self):
|
|
|
|
- return self._request("disable_events")
|
|
|
|
-
|
|
|
|
def ping(self):
|
|
def ping(self):
|
|
return self._request("ping")
|
|
return self._request("ping")
|
|
|
|
|
|
- def add_consumer(self, queue, exchange=None, exchange_type="direct",
|
|
|
|
- routing_key=None, **options):
|
|
|
|
- return self._request("add_consumer", queue=queue, exchange=exchange,
|
|
|
|
- exchange_type=exchange_type,
|
|
|
|
- routing_key=routing_key, **options)
|
|
|
|
-
|
|
|
|
- def cancel_consumer(self, queue, **kwargs):
|
|
|
|
- return self._request("cancel_consumer", queue=queue, **kwargs)
|
|
|
|
-
|
|
|
|
def active_queues(self):
|
|
def active_queues(self):
|
|
return self._request("active_queues")
|
|
return self._request("active_queues")
|
|
|
|
|
|
@@ -124,7 +109,7 @@ class Control(object):
|
|
|
|
|
|
def revoke(self, task_id, destination=None, terminate=False,
|
|
def revoke(self, task_id, destination=None, terminate=False,
|
|
signal="SIGTERM", **kwargs):
|
|
signal="SIGTERM", **kwargs):
|
|
- """Revoke a task by id.
|
|
|
|
|
|
+ """Tell all (or specific) workers to revoke a task by id.
|
|
|
|
|
|
If a task is revoked, the workers will ignore the task and
|
|
If a task is revoked, the workers will ignore the task and
|
|
not execute it after all.
|
|
not execute it after all.
|
|
@@ -134,13 +119,8 @@ class Control(object):
|
|
on the task (if any).
|
|
on the task (if any).
|
|
:keyword signal: Name of signal to send to process if terminate.
|
|
:keyword signal: Name of signal to send to process if terminate.
|
|
Default is TERM.
|
|
Default is TERM.
|
|
- :keyword destination: If set, a list of the hosts to send the
|
|
|
|
- command to, when empty broadcast to all workers.
|
|
|
|
- :keyword connection: Custom broker connection to use, if not set,
|
|
|
|
- a connection will be established automatically.
|
|
|
|
- :keyword reply: Wait for and return the reply.
|
|
|
|
- :keyword timeout: Timeout in seconds to wait for the reply.
|
|
|
|
- :keyword limit: Limit number of replies.
|
|
|
|
|
|
+
|
|
|
|
+ See :meth:`broadcast` for supported keyword arguments.
|
|
|
|
|
|
"""
|
|
"""
|
|
return self.broadcast("revoke", destination=destination,
|
|
return self.broadcast("revoke", destination=destination,
|
|
@@ -149,37 +129,27 @@ class Control(object):
|
|
"signal": signal}, **kwargs)
|
|
"signal": signal}, **kwargs)
|
|
|
|
|
|
def ping(self, destination=None, timeout=1, **kwargs):
|
|
def ping(self, destination=None, timeout=1, **kwargs):
|
|
- """Ping workers.
|
|
|
|
|
|
+ """Ping all (or specific) workers.
|
|
|
|
|
|
Returns answer from alive workers.
|
|
Returns answer from alive workers.
|
|
|
|
|
|
- :keyword destination: If set, a list of the hosts to send the
|
|
|
|
- command to, when empty broadcast to all workers.
|
|
|
|
- :keyword connection: Custom broker connection to use, if not set,
|
|
|
|
- a connection will be established automatically.
|
|
|
|
- :keyword reply: Wait for and return the reply.
|
|
|
|
- :keyword timeout: Timeout in seconds to wait for the reply.
|
|
|
|
- :keyword limit: Limit number of replies.
|
|
|
|
|
|
+ See :meth:`broadcast` for supported keyword arguments.
|
|
|
|
|
|
"""
|
|
"""
|
|
return self.broadcast("ping", reply=True, destination=destination,
|
|
return self.broadcast("ping", reply=True, destination=destination,
|
|
timeout=timeout, **kwargs)
|
|
timeout=timeout, **kwargs)
|
|
|
|
|
|
def rate_limit(self, task_name, rate_limit, destination=None, **kwargs):
|
|
def rate_limit(self, task_name, rate_limit, destination=None, **kwargs):
|
|
- """Set rate limit for task by type.
|
|
|
|
|
|
+ """Tell all (or specific) workers to set a new rate limit
|
|
|
|
+ for task by type.
|
|
|
|
|
|
:param task_name: Name of task to change rate limit for.
|
|
:param task_name: Name of task to change rate limit for.
|
|
:param rate_limit: The rate limit as tasks per second, or a rate limit
|
|
:param rate_limit: The rate limit as tasks per second, or a rate limit
|
|
string (`"100/m"`, etc.
|
|
string (`"100/m"`, etc.
|
|
see :attr:`celery.task.base.Task.rate_limit` for
|
|
see :attr:`celery.task.base.Task.rate_limit` for
|
|
more information).
|
|
more information).
|
|
- :keyword destination: If set, a list of the hosts to send the
|
|
|
|
- command to, when empty broadcast to all workers.
|
|
|
|
- :keyword connection: Custom broker connection to use, if not set,
|
|
|
|
- a connection will be established automatically.
|
|
|
|
- :keyword reply: Wait for and return the reply.
|
|
|
|
- :keyword timeout: Timeout in seconds to wait for the reply.
|
|
|
|
- :keyword limit: Limit number of replies.
|
|
|
|
|
|
+
|
|
|
|
+ See :meth:`broadcast` for supported keyword arguments.
|
|
|
|
|
|
"""
|
|
"""
|
|
return self.broadcast("rate_limit", destination=destination,
|
|
return self.broadcast("rate_limit", destination=destination,
|
|
@@ -187,8 +157,46 @@ class Control(object):
|
|
"rate_limit": rate_limit},
|
|
"rate_limit": rate_limit},
|
|
**kwargs)
|
|
**kwargs)
|
|
|
|
|
|
|
|
+ def add_consumer(self, queue, exchange=None, exchange_type="direct",
|
|
|
|
+ routing_key=None, **options):
|
|
|
|
+ """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.
|
|
|
|
+
|
|
|
|
+ :param queue: Name of queue to start consuming from.
|
|
|
|
+ :keyword exchange: Optional name of exchange.
|
|
|
|
+ :keyword exchange_type: Type of exchange (defaults to "direct")
|
|
|
|
+ command to, when empty broadcast to all workers.
|
|
|
|
+ :keyword routing_key: Optional routing key.
|
|
|
|
+
|
|
|
|
+ See :meth:`broadcast` for supported keyword arguments.
|
|
|
|
+
|
|
|
|
+ """
|
|
|
|
+ return self.broadcast("add_consumer",
|
|
|
|
+ arguments={"queue": queue, "exchange": exchange,
|
|
|
|
+ "exchange_type": exchange_type,
|
|
|
|
+ "routing_key": routing_key}, **options)
|
|
|
|
+
|
|
|
|
+ def cancel_consumer(self, queue, **kwargs):
|
|
|
|
+ """Tell all (or specific) workers to stop consuming from ``queue``.
|
|
|
|
+
|
|
|
|
+ Supports the same keyword arguments as :meth:`broadcast`.
|
|
|
|
+
|
|
|
|
+ """
|
|
|
|
+ return self.broadcast("cancel_consumer",
|
|
|
|
+ arguments={"queue": queue}, **kwargs)
|
|
|
|
+
|
|
|
|
+
|
|
def time_limit(self, task_name, soft=None, hard=None, **kwargs):
|
|
def time_limit(self, task_name, soft=None, hard=None, **kwargs):
|
|
- """Set time limits for task by type.
|
|
|
|
|
|
+ """Tell all (or specific) workers to set time limits for
|
|
|
|
+ a task by type.
|
|
|
|
|
|
:param task_name: Name of task to change time limits for.
|
|
:param task_name: Name of task to change time limits for.
|
|
:keyword soft: New soft time limit (in seconds).
|
|
:keyword soft: New soft time limit (in seconds).
|
|
@@ -199,12 +207,35 @@ class Control(object):
|
|
"""
|
|
"""
|
|
return self.broadcast("time_limit",
|
|
return self.broadcast("time_limit",
|
|
arguments={"task_name": task_name,
|
|
arguments={"task_name": task_name,
|
|
- "hard": hard, "soft": soft},
|
|
|
|
- **kwargs)
|
|
|
|
|
|
+ "hard": hard, "soft": soft}, **kwargs)
|
|
|
|
+
|
|
|
|
+ def enable_events(self, destination=None, **kwargs):
|
|
|
|
+ """Tell all (or specific) workers to enable events."""
|
|
|
|
+ return self.broadcast("enable_events", {}, destination, **kwargs)
|
|
|
|
+
|
|
|
|
+ def disable_events(self, destination=None, **kwargs):
|
|
|
|
+ """Tell all (or specific) workers to enable events."""
|
|
|
|
+ return self.broadcast("disable_events", {}, destination, **kwargs)
|
|
|
|
+
|
|
|
|
+ def pool_grow(self, n=1, destination=None, **kwargs):
|
|
|
|
+ """Tell all (or specific) workers to grow the pool by ``n``.
|
|
|
|
+
|
|
|
|
+ Supports the same arguments as :meth:`broadcast`.
|
|
|
|
+
|
|
|
|
+ """
|
|
|
|
+ return self.broadcast("pool_grow", {}, destination, **kwargs)
|
|
|
|
+
|
|
|
|
+ def pool_shrink(self, n=1, destination=None, **kwargs):
|
|
|
|
+ """Tell all (or specific) workers to shrink the pool by ``n``.
|
|
|
|
+
|
|
|
|
+ Supports the same arguments as :meth:`broadcast`.
|
|
|
|
+
|
|
|
|
+ """
|
|
|
|
+ return self.broadcast("pool_shrink", {}, destination, **kwargs)
|
|
|
|
|
|
def broadcast(self, command, arguments=None, destination=None,
|
|
def broadcast(self, command, arguments=None, destination=None,
|
|
connection=None, reply=False, timeout=1, limit=None,
|
|
connection=None, reply=False, timeout=1, limit=None,
|
|
- callback=None, channel=None):
|
|
|
|
|
|
+ callback=None, channel=None, **extra_kwargs):
|
|
"""Broadcast a control command to the celery workers.
|
|
"""Broadcast a control command to the celery workers.
|
|
|
|
|
|
:param command: Name of command to send.
|
|
:param command: Name of command to send.
|
|
@@ -223,6 +254,7 @@ class Control(object):
|
|
with self.app.default_connection(connection) as conn:
|
|
with self.app.default_connection(connection) as conn:
|
|
if channel is None:
|
|
if channel is None:
|
|
channel = conn.default_channel
|
|
channel = conn.default_channel
|
|
|
|
+ arguments = dict(arguments, **extra_kwargs)
|
|
return self.mailbox(conn)._broadcast(command, arguments,
|
|
return self.mailbox(conn)._broadcast(command, arguments,
|
|
destination, reply, timeout,
|
|
destination, reply, timeout,
|
|
limit, callback,
|
|
limit, callback,
|