GCSBackendBase
Google Cloud Storage task result backend.
Attributes
| Attribute | Type | Description |
|---|---|---|
| _client_lock | RLock | Reentrant lock used to ensure thread-safe access and initialization of the Google Cloud Storage client. |
| _pid | int | The process ID of the current process, used to detect forks and ensure each process maintains its own client connection. |
| _retry_policy | google.api_core.retry.Retry = DEFAULT_RETRY | The retry policy applied to Google Cloud Storage operations like downloading, uploading, or deleting blobs. |
| _client | google.cloud.storage.client.Client = null | Internal cache for the Google Cloud Storage client instance. |
| bucket_name | string | The name of the Google Cloud Storage bucket where task results are stored. |
| project | string | The Google Cloud project ID associated with the storage bucket. |
| base_path | string = "" | A prefix path within the bucket used to namespace stored task results. |
| _threadpool_maxsize | int = 10 | The maximum number of concurrent connections allowed in the HTTP adapter pool for the storage client. |
| ttl | float = 0 | The time-to-live in seconds for stored results, requiring a corresponding bucket lifecycle rule if non-zero. |
| client | google.cloud.storage.client.Client | Returns a storage client. |
| bucket | google.cloud.storage.bucket.Bucket | The Google Cloud Storage bucket object derived from the configured bucket name and client. |
Constructor
Signature
def GCSBackendBase(
**kwargs: dict
)
Parameters
| Name | Type | Description |
|---|---|---|
| **kwargs | dict | Arbitrary keyword arguments passed to the parent KeyValueStoreBackend class. |
Methods
get()
@classmethod
def get(
key: string
) - > bytes
Retrieves the binary content of a specific object from the GCS bucket. Returns None if the object does not exist.
Parameters
| Name | Type | Description |
|---|---|---|
| key | string | The unique identifier for the object to retrieve from the storage bucket. |
Returns
| Type | Description |
|---|---|
bytes | The raw bytes downloaded from the GCS blob, or None if the key is not found. |
set()
@classmethod
def set(
key: string,
value: string
) - > null
Uploads data to a GCS blob and optionally sets a custom expiration time if a TTL is configured.
Parameters
| Name | Type | Description |
|---|---|---|
| key | string | The destination path or name for the object in the GCS bucket. |
| value | string | The data content to be uploaded to the storage backend. |
Returns
| Type | Description |
|---|---|
null | No return value. |
delete()
@classmethod
def delete(
key: string
) - > null
Removes an object from the GCS bucket if it exists.
Parameters
| Name | Type | Description |
|---|---|---|
| key | string | The identifier of the object to be deleted from storage. |
Returns
| Type | Description |
|---|---|
null | No return value. |
mget()
@classmethod
def mget(
keys: list
) - > list
Fetches multiple objects concurrently using a thread pool to improve performance for batch operations.
Parameters
| Name | Type | Description |
|---|---|---|
| keys | list | A collection of object identifiers to retrieve from the bucket. |
Returns
| Type | Description |
|---|---|
list | A list of byte strings corresponding to the requested keys, in the same order as provided. |
client()
@classmethod
def client() - > google.cloud.storage.client.Client
Returns a storage client.
Returns
| Type | Description |
|---|---|
google.cloud.storage.client.Client | A thread-safe GCS client instance configured with connection pooling and process-specific sessions. |
bucket()
@classmethod
def bucket() - > google.cloud.storage.bucket.Bucket
Accesses the specific GCS bucket instance configured for this backend.
Returns
| Type | Description |
|---|---|
google.cloud.storage.bucket.Bucket | The bucket object used for all storage operations. |