class AsyncLockBlob: _name = "Azure Blob" def __init__(self, client: AsyncBlobClient, duration: int): self._client = client self._duration = duration self.id = str(uuid4()) self._lock = AsyncBlobLeaseClient(self._client, lease_id=self.id) self.account_name = self._client.account_name self.target = self._client.primary_hostname self.url = "{}://{}/{}/{}".format( self._client.scheme, self._client.primary_hostname, quote(self._client.container_name), quote(self._client.blob_name, safe='~/'), ) async def __aenter__(self): await self.acquire() return self async def __aexit__(self, exc_type, exc_val, exc_tb): await self.release() @trace_async_method_operation( "container", "path", "target", name="account_name", dep_type="_name", action="release_lock", operation="PUT" ) def release(self): return self._lock.release() @trace_async_method_operation( "container", "path", "target", name="account_name", dep_type="_name", action="set_lock", operation="PUT" ) def acquire(self): return self._lock.acquire(self._duration) @trace_async_method_operation( "container", "path", "target", name="account_name", dep_type="_name", action="renew_lock", operation="PUT" ) def renew(self): return self._lock.renew()
class AsyncLockBlob: def __init__(self, client: AsyncBlobClient, duration: int): self._client = client self._duration = duration self.id = str(uuid4()) self._lock = AsyncBlobLeaseClient(self._client, lease_id=self.id) async def __aenter__(self): await self.acquire() return self async def __aexit__(self, exc_type, exc_val, exc_tb): await self.release() def release(self): return self._lock.release() def acquire(self): return self._lock.acquire(self._duration) def renew(self): return self._lock.renew()