def broadcast(command, arguments=None, destination=None, connection=None, connect_timeout=conf.BROKER_CONNECTION_TIMEOUT, reply=False, timeout=1, limit=None, callback=None): """Broadcast a control command to the celery workers. :param command: Name of command to send. :param arguments: Keyword arguments for the command. :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 connect_timeout: Timeout for new connection if a custom connection is not provided. :keyword reply: Wait for and return the reply. :keyword timeout: Timeout in seconds to wait for the reply. :keyword limit: Limit number of replies. :keyword callback: Callback called immediately for each reply received. """ arguments = arguments or {} reply_ticket = reply and gen_unique_id() or None if destination is not None and not isinstance(destination, (list, tuple)): raise ValueError("destination must be a list/tuple not %s" % ( type(destination))) # Set reply limit to number of destinations (if specificed) if limit is None and destination: limit = destination and len(destination) or None crq = None if reply_ticket: crq = ControlReplyConsumer(connection, reply_ticket) broadcast = BroadcastPublisher(connection) try: broadcast.send(command, arguments, destination=destination, reply_ticket=reply_ticket) finally: broadcast.close() if crq: try: return crq.collect(limit=limit, timeout=timeout, callback=callback) finally: crq.close()
def broadcast(command, arguments=None, destination=None, connection=None, connect_timeout=conf.BROKER_CONNECTION_TIMEOUT): """Broadcast a control command to the celery workers. :param command: Name of command to send. :param arguments: Keyword arguments for the command. :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 connect_timeout: Timeout for new connection if a custom connection is not provided. """ arguments = arguments or {} broadcast = BroadcastPublisher(connection) try: broadcast.send(command, arguments, destination=destination) finally: broadcast.close()
def broadcast(command, arguments=None, destination=None, connection=None, connect_timeout=conf.BROKER_CONNECTION_TIMEOUT, reply=False, timeout=1, limit=None): """Broadcast a control command to the celery workers. :param command: Name of command to send. :param arguments: Keyword arguments for the command. :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 connect_timeout: Timeout for new connection if a custom connection is not provided. :keyword reply: Wait for and return the reply. :keyword timeout: Timeout in seconds to wait for the reply. :keyword limit: Limit number of replies. """ arguments = arguments or {} reply_ticket = reply and gen_unique_id() or None if destination is not None and not isinstance(destination, (list, tuple)): raise ValueError("destination must be a list/tuple not %s" % (type(destination))) # Set reply limit to number of destinations (if specificed) if limit is None and destination: limit = destination and len(destination) or None broadcast = BroadcastPublisher(connection) try: broadcast.send(command, arguments, destination=destination, reply_ticket=reply_ticket) finally: broadcast.close() if reply_ticket: crq = ControlReplyConsumer(connection, reply_ticket) try: return crq.collect(limit=limit, timeout=timeout) finally: crq.close()
def _revoke(connection): broadcast = BroadcastPublisher(connection) try: broadcast.revoke(task_id) finally: broadcast.close()