async def release_lease_async(self, lease):
     """
     Give up a lease currently held by this host. If the lease has been stolen, or expired,
     releasing it is unnecessary, and will fail if attempted.
     :returns: `True` if the lease was released successfully, `False` if not.
     """
     lease_id = None
     try:
         _logger.info("Releasing lease {} {}".format(
             self.host.guid, lease.partition_id))
         lease_id = lease.token
         released_copy = AzureBlobLease()
         released_copy.with_lease(lease)
         released_copy.token = None
         released_copy.owner = None
         released_copy.state = None
         await self.host.loop.run_in_executor(
             self.executor,
             functools.partial(self.storage_client.create_blob_from_text,
                               self.lease_container_name,
                               lease.partition_id,
                               json.dumps(released_copy.serializable()),
                               lease_id=lease_id))
         await self.host.loop.run_in_executor(
             self.executor,
             functools.partial(self.storage_client.release_blob_lease,
                               self.lease_container_name,
                               lease.partition_id, lease_id))
     except Exception as err:  # pylint: disable=broad-except
         _logger.error("Failed to release lease {} {} {}".format(
             err, lease.partition_id, lease_id))
         return False
     return True
예제 #2
0
    async def release_lease_async(self, lease):
        """
        Give up a lease currently held by this host. If the lease has been stolen, or expired,
        releasing it is unnecessary, and will fail if attempted.

        :param lease: The stored lease to be released.
        :type lease: ~azure.eventprocessorhost.lease.Lease
        :return: `True` if the lease was released successfully, `False` if not.
        :rtype: bool
        """
        lease_id = None
        try:
            _logger.info("Releasing lease %r %r", self.host.guid,
                         lease.partition_id)
            lease_id = lease.token
            released_copy = AzureBlobLease()
            released_copy.with_lease(lease)
            released_copy.token = None
            released_copy.owner = None
            released_copy.state = None
            await self.host.loop.run_in_executor(
                self.executor,
                functools.partial(
                    self.storage_client.create_blob_from_text,
                    #self.lease_container_name,
                    self.lease_container_name + '/' +
                    self.consumer_group_directory,
                    lease.partition_id,
                    json.dumps(released_copy.serializable()),
                    lease_id=lease_id))
            await self.host.loop.run_in_executor(
                self.executor,
                functools.partial(
                    self.storage_client.release_blob_lease,
                    #self.lease_container_name,
                    self.lease_container_name + '/' +
                    self.consumer_group_directory,
                    lease.partition_id,
                    lease_id))
        except Exception as err:  # pylint: disable=broad-except
            _logger.error("Failed to release lease %r %r %r", err,
                          lease.partition_id, lease_id)
            return False
        return True
    async def release_lease_async(self, lease):
        """
        Give up a lease currently held by this host. If the lease has been stolen, or expired,
        releasing it is unnecessary, and will fail if attempted.

        :param lease: The stored lease to be released.
        :type lease: ~azure.eventprocessorhost.lease.Lease
        :return: `True` if the lease was released successfully, `False` if not.
        :rtype: bool
        """
        lease_id = None
        try:
            _logger.info("Releasing lease %r %r", self.host.guid, lease.partition_id)
            lease_id = lease.token
            released_copy = AzureBlobLease()
            released_copy.with_lease(lease)
            released_copy.token = None
            released_copy.owner = None
            released_copy.state = None
            await self.host.loop.run_in_executor(
                self.executor,
                functools.partial(
                    self.storage_client.create_blob_from_text,
                    self.lease_container_name,
                    lease.partition_id,
                    json.dumps(released_copy.serializable()),
                    lease_id=lease_id))
            await self.host.loop.run_in_executor(
                self.executor,
                functools.partial(
                    self.storage_client.release_blob_lease,
                    self.lease_container_name,
                    lease.partition_id,
                    lease_id))
        except Exception as err:  # pylint: disable=broad-except
            _logger.error("Failed to release lease %r %r %r",
                          err, lease.partition_id, lease_id)
            return False
        return True