示例#1
0
 def _get_amqp_client(self):
     if self.cluster:
         # if the active manager dies during agent installation, only then
         # we will need to look for the new active here; in most cases, the
         # first one from the self.cluster list will be online, and that
         # is equal to just using self.broker_url/self.broker_ip
         err = None
         for node in self.cluster:
             try:
                 return amqp_client.create_client(
                     amqp_host=node['broker_ip'],
                     amqp_user=node['broker_user'],
                     amqp_pass=node['broker_pass'],
                     ssl_enabled=node['broker_ssl_enabled'],
                     ssl_cert_path=node.get('internal_cert_path'))
             except AMQPConnectionError as err:
                 continue
         if err:
             raise err
     else:
         return amqp_client.create_client(
             amqp_host=self.broker_ip,
             amqp_user=self.broker_user,
             amqp_pass=self.broker_pass,
             ssl_enabled=self.broker_ssl_enabled,
             ssl_cert_path=self.broker_ssl_cert_path)
 def wrapped_target():
     client = amqp_client.create_client()
     self.started_amqp_client.put_nowait(True)
     thread_storage.amqp_client = client
     try:
         self.target_method()
     finally:
         client.close()
 def wrapped_target():
     client = amqp_client.create_client()
     self.started_amqp_client.put_nowait(True)
     thread_storage.amqp_client = client
     try:
         self.target_method()
     finally:
         client.close()
示例#4
0
def _amqp_client():
    """
    Get an AMQPClient for the current thread. If non currently exists,
    create one.

    :return: An AMQPClient belonging to the current thread
    """
    if not hasattr(clients, 'amqp_client'):
        clients.amqp_client = create_client()
    return clients.amqp_client
示例#5
0
def _amqp_client():
    """
    Get an AMQPClient for the current thread. If non currently exists,
    create one.

    :return: An AMQPClient belonging to the current thread
    """
    if not hasattr(clients, 'amqp_client'):
        clients.amqp_client = create_client()
    return clients.amqp_client
示例#6
0
 def wrapper(*args, **kwargs):
     """
     Calls the wrapped func with an AMQP client instance.
     Attempts to use a thread-local AMQP client, if exists; otherwise
     creates a new client and closes it after use.
     """
     # get an amqp client from the thread or create a new one
     fresh_client = False
     client = amqp_client_utils.get_amqp_client()
     if not client:
         client = amqp_client.create_client()
         fresh_client = True
     # call the wrapped func with the amqp client
     try:
         func(client, *args, **kwargs)
     except ClosedAMQPClientException:
         # the client has been closed, create a new one and call again
         client = amqp_client.create_client()
         fresh_client = True
         func(client, *args, **kwargs)
     finally:
         if fresh_client:
             client.close()
示例#7
0
文件: logs.py 项目: Fleuri/pythontest
 def wrapper(*args, **kwargs):
     """
     Calls the wrapped func with an AMQP client instance.
     Attempts to use a thread-local AMQP client, if exists; otherwise
     creates a new client and closes it after use.
     """
     # get an amqp client from the thread or create a new one
     fresh_client = False
     client = amqp_client_utils.get_amqp_client()
     if not client:
         client = amqp_client.create_client()
         fresh_client = True
     # call the wrapped func with the amqp client
     try:
         func(client, *args, **kwargs)
     except ClosedAMQPClientException:
         # the client has been closed, create a new one and call again
         client = amqp_client.create_client()
         fresh_client = True
         func(client, *args, **kwargs)
     finally:
         if fresh_client:
             client.close()
示例#8
0
 def _delete_amqp_queues(self):
     client = amqp_client.create_client(self.broker_ip)
     try:
         channel = client.connection.channel()
         self._logger.debug('Deleting queue: {0}'.format(self.queue))
         channel.queue_delete(self.queue)
         pid_box_queue = 'celery@{0}.celery.pidbox'.format(self.queue)
         self._logger.debug('Deleting queue: {0}'.format(pid_box_queue))
         channel.queue_delete(pid_box_queue)
     finally:
         try:
             client.close()
         except Exception as e:
             self._logger.warning('Failed closing amqp client: {0}'
                                  .format(e))
示例#9
0
def _amqp_client(ctx):
    """
    Get an AMQPClient for the current thread. If non currently exists,
    create one.

    :param ctx: The context, used to get AMQP credentials and SSL settings.

    :return: An AMQPClient belonging to the current thread.
             Will return a pre-existing one without re-initialising even if
             called with new arguments a second or subsequent time.
    """
    if not hasattr(clients, 'amqp_client'):
        clients.amqp_client = create_client(
            amqp_host=broker_config.broker_hostname,
            amqp_user=broker_config.broker_username,
            amqp_pass=broker_config.broker_password,
            ssl_enabled=broker_config.broker_ssl_enabled,
            ssl_cert_path=broker_config.broker_cert_path)
    return clients.amqp_client
def _delete_amqp_queues(worker_name):
    # FIXME: this function deletes amqp queues that will be used by worker.
    # The amqp queues used by celery worker are determined by worker name
    # and if there are multiple workers with same name celery gets confused.
    #
    # Currently the worker name is based solely on hostname, so it will be
    # re-used if vm gets re-created by auto-heal.
    # Deleting the queues is a workaround for celery problems this creates.
    # Having unique worker names is probably a better long-term strategy.
    client = amqp_client.create_client()
    try:
        channel = client.connection.channel()

        # celery worker queue
        channel.queue_delete(worker_name)

        # celery management queue
        channel.queue_delete('celery@{0}.celery.pidbox'.format(worker_name))
    finally:
        try:
            client.close()
        except Exception:
            pass
示例#11
0
    def _delete_amqp_queues(self):
        client = amqp_client.create_client(
            amqp_host=self.broker_ip,
            amqp_user=self.broker_user,
            amqp_pass=self.broker_pass,
            ssl_enabled=self.broker_ssl_enabled,
            ssl_cert_path=self.broker_ssl_cert_path,
        )

        try:
            channel = client.connection.channel()
            self._logger.debug('Deleting queue: {0}'.format(self.queue))

            channel.queue_delete(self.queue)
            pid_box_queue = 'celery@{0}.celery.pidbox'.format(self.name)
            self._logger.debug('Deleting queue: {0}'.format(pid_box_queue))
            channel.queue_delete(pid_box_queue)
        finally:
            try:
                client.close()
            except Exception as e:
                self._logger.warning('Failed closing amqp client: {0}'
                                     .format(e))
示例#12
0
def _delete_amqp_queues(worker_name):
    # FIXME: this function deletes amqp queues that will be used by worker.
    # The amqp queues used by celery worker are determined by worker name
    # and if there are multiple workers with same name celery gets confused.
    #
    # Currently the worker name is based solely on hostname, so it will be
    # re-used if vm gets re-created by auto-heal.
    # Deleting the queues is a workaround for celery problems this creates.
    # Having unique worker names is probably a better long-term strategy.
    client = amqp_client.create_client()
    try:
        channel = client.connection.channel()

        # celery worker queue
        channel.queue_delete(worker_name)

        # celery management queue
        channel.queue_delete('celery@{0}.celery.pidbox'.format(worker_name))
    finally:
        try:
            client.close()
        except Exception:
            pass
def init_amqp_client():
    thread_storage.amqp_client = amqp_client.create_client()
def init_amqp_client():
    thread_storage.amqp_client = amqp_client.create_client()
 def _make_client(self):
     return amqp_client.create_client(*self._client_args,
                                      **self._client_kwargs)
示例#16
0
 def _make_client(self):
     return amqp_client.create_client(*self._client_args,
                                      **self._client_kwargs)