async def create_lease_if_not_exists_async(self, partition_id): """ Create in the store the lease info for the given partition, if it does not exist. Do nothing if it does exist in the store already. :param partition_id: The ID of a given parition. :type partition_id: str :return: the existing or newly-created lease info for the partition. :rtype: ~azure.eventprocessorhost.lease.Lease """ return_lease = None try: return_lease = AzureBlobLease() return_lease.partition_id = partition_id serializable_lease = return_lease.serializable() json_lease = json.dumps(serializable_lease) _logger.info("Creating Lease %r %r %r", self.lease_container_name, partition_id, json.dumps({k:v for k, v in serializable_lease.items() if k != 'event_processor_context'})) await self.host.loop.run_in_executor( self.executor, functools.partial( self.storage_client.create_blob_from_text, self.lease_container_name, partition_id, json_lease)) except Exception: # pylint: disable=broad-except try: return_lease = await self.get_lease_async(partition_id) except Exception as err: # pylint: disable=broad-except _logger.error("Failed to create lease %r", err) raise err return return_lease
async def create_lease_if_not_exists_async(self, partition_id): """ Create in the store the lease info for the given partition, if it does not exist. Do nothing if it does exist in the store already. :param partition_id: The ID of a given parition. :type partition_id: str :return: the existing or newly-created lease info for the partition. :rtype: ~azure.eventprocessorhost.lease.Lease """ return_lease = None try: return_lease = AzureBlobLease() return_lease.partition_id = partition_id json_lease = json.dumps(return_lease.serializable()) _logger.info("Creating Lease {} {} {}".format( self.lease_container_name, partition_id, json_lease)) await self.host.loop.run_in_executor( self.executor, functools.partial( self.storage_client.create_blob_from_text, self.lease_container_name, partition_id, json_lease)) except Exception: # pylint: disable=broad-except try: return_lease = await self.get_lease_async(partition_id) except Exception as err: # pylint: disable=broad-except _logger.error("Failed to create lease {!r}".format(err)) raise err return return_lease
async def create_lease_if_not_exists_async(self, partition_id): """ Create in the store the lease info for the given partition, if it does not exist. Do nothing if it does exist in the store already. :param partition_id: The ID of a given parition. :type partition_id: str :return: the existing or newly-created lease info for the partition. :rtype: ~azure.eventprocessorhost.lease.Lease """ return_lease = None try: return_lease = AzureBlobLease() return_lease.partition_id = partition_id serializable_lease = return_lease.serializable() json_lease = json.dumps(serializable_lease) _logger.info( "Creating Lease %r %r %r", self.lease_container_name, partition_id, json.dumps({ k: v for k, v in serializable_lease.items() if k != 'event_processor_context' })) await self.host.loop.run_in_executor( self.executor, functools.partial( self.storage_client.create_blob_from_text, self.lease_container_name + '/' + self.consumer_group_directory, #self.lease_container_name, partition_id, json_lease)) except Exception: # pylint: disable=broad-except try: return_lease = await self.get_lease_async(partition_id) except Exception as err: # pylint: disable=broad-except _logger.error("Failed to create lease %r", err) raise err return return_lease