Ejemplo n.º 1
0
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()
    def __init__(self, client, lease_id=None):  # pylint: disable=missing-client-constructor-parameter-credential,missing-client-constructor-parameter-kwargs
        # type: (Union[FileSystemClient, DataLakeDirectoryClient, DataLakeFileClient], Optional[str]) -> None
        super(DataLakeLeaseClient, self).__init__(client, lease_id)

        if hasattr(client, '_blob_client'):
            _client = client._blob_client  # type: ignore # pylint: disable=protected-access
        elif hasattr(client, '_container_client'):
            _client = client._container_client  # type: ignore # pylint: disable=protected-access
        else:
            raise TypeError(
                "Lease must use any of FileSystemClient DataLakeDirectoryClient, or DataLakeFileClient."
            )

        self._blob_lease_client = BlobLeaseClient(_client, lease_id=lease_id)
Ejemplo n.º 4
0
    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='~/'),
        )
 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)