88import gzip
99import logging
1010import uuid
11- from typing import Any , Optional
11+ from typing import Optional
1212
1313from azure .storage .blob import BlobServiceClient
1414from azure .storage .blob .aio import BlobServiceClient as AsyncBlobServiceClient
1515
16- from durabletask .payload .store import LargePayloadStorageOptions , PayloadStore
16+ from durabletask .extensions .azure_blob_payloads .options import BlobPayloadStoreOptions
17+ from durabletask .payload .store import PayloadStore
1718
1819logger = logging .getLogger ("durabletask-blobpayloads" )
1920
@@ -29,79 +30,60 @@ class BlobPayloadStore(PayloadStore):
2930 token format (``blob:v1:<container>:<blobName>``) and the same
3031 storage layout, allowing cross-language interoperability.
3132
33+ Example::
34+
35+ store = BlobPayloadStore(BlobPayloadStoreOptions(
36+ connection_string="...",
37+ ))
38+
3239 Args:
33- connection_string: Azure Storage connection string. Mutually
34- exclusive with *account_url*.
35- account_url: Azure Storage account URL. Must be combined with
36- *credential*.
37- credential: A ``TokenCredential`` for token-based auth.
38- container_name: Blob container for externalized payloads.
39- threshold_bytes: Payloads larger than this are externalized.
40- max_stored_payload_bytes: Maximum externalized payload size.
41- enable_compression: GZip-compress payloads before uploading.
42- api_version: Azure Storage API version override (useful for
43- Azurite compatibility).
40+ options: A :class:`BlobPayloadStoreOptions` with all settings.
4441 """
4542
46- def __init__ (
47- self ,
48- * ,
49- connection_string : Optional [str ] = None ,
50- account_url : Optional [str ] = None ,
51- credential : Any = None ,
52- container_name : str = "durabletask-payloads" ,
53- threshold_bytes : int = 900_000 ,
54- max_stored_payload_bytes : int = 10 * 1024 * 1024 ,
55- enable_compression : bool = True ,
56- api_version : Optional [str ] = None ,
57- ):
58- if not connection_string and not account_url :
43+ def __init__ (self , options : BlobPayloadStoreOptions ):
44+ if not options .connection_string and not options .account_url :
5945 raise ValueError (
6046 "Either 'connection_string' or 'account_url' (with 'credential') must be provided."
6147 )
6248
63- self ._options = LargePayloadStorageOptions (
64- threshold_bytes = threshold_bytes ,
65- max_stored_payload_bytes = max_stored_payload_bytes ,
66- enable_compression = enable_compression ,
67- )
68- self ._container_name = container_name
49+ self ._options = options
50+ self ._container_name = options .container_name
6951
7052 # Optional kwargs shared by both sync and async clients.
7153 extra_kwargs : dict = {}
72- if api_version :
73- extra_kwargs ["api_version" ] = api_version
54+ if options . api_version :
55+ extra_kwargs ["api_version" ] = options . api_version
7456
7557 # Build sync client
76- if connection_string :
58+ if options . connection_string :
7759 self ._blob_service_client = BlobServiceClient .from_connection_string (
78- connection_string , ** extra_kwargs ,
60+ options . connection_string , ** extra_kwargs ,
7961 )
8062 else :
81- assert account_url is not None # guaranteed by validation above
63+ assert options . account_url is not None # guaranteed by validation above
8264 self ._blob_service_client = BlobServiceClient (
83- account_url = account_url ,
84- credential = credential ,
65+ account_url = options . account_url ,
66+ credential = options . credential ,
8567 ** extra_kwargs ,
8668 )
8769
8870 # Build async client
89- if connection_string :
71+ if options . connection_string :
9072 self ._async_blob_service_client = AsyncBlobServiceClient .from_connection_string (
91- connection_string , ** extra_kwargs ,
73+ options . connection_string , ** extra_kwargs ,
9274 )
9375 else :
94- assert account_url is not None # guaranteed by validation above
76+ assert options . account_url is not None # guaranteed by validation above
9577 self ._async_blob_service_client = AsyncBlobServiceClient (
96- account_url = account_url ,
97- credential = credential ,
78+ account_url = options . account_url ,
79+ credential = options . credential ,
9880 ** extra_kwargs ,
9981 )
10082
10183 self ._ensure_container_created = False
10284
10385 @property
104- def options (self ) -> LargePayloadStorageOptions :
86+ def options (self ) -> BlobPayloadStoreOptions :
10587 return self ._options
10688
10789 # ------------------------------------------------------------------
0 commit comments