Persistent
Stores worker state between restarts. This is the persistent data stored by the worker when :option:celery worker --statedb is enabled. Currently only stores revoked task id's.
Attributes
| Attribute | Type | Description |
|---|---|---|
| storage | module = shelve | The storage module or interface used to open the persistent database file, defaulting to the standard library shelve module. |
| protocol | int = pickle_protocol | The pickle protocol version used for serializing and deserializing the persistent state data. |
| compress | callable = zlib.compress | The compression function used to reduce the size of the revoked task data before it is stored in the database. |
| decompress | callable = zlib.decompress | The decompression function used to restore compressed revoked task data retrieved from the database. |
Constructor
Signature
def Persistent(
state: Any,
filename: str,
clock: Any = None
)
Parameters
| Name | Type | Description |
|---|---|---|
| state | Any | The worker state object containing revoked tasks. |
| filename | str | The path to the database file used for persistence. |
| clock | Any = None | An optional logical clock for synchronization. |
Methods
open()
@classmethod
def open() - > shelve.DbfilenameShelf
Opens the underlying shelf storage file using the configured protocol and writeback settings.
Returns
| Type | Description |
|---|---|
shelve.DbfilenameShelf | A shelf object providing dictionary-like access to the persistent storage file. |
merge()
@classmethod
def merge() - > null
Synchronizes the current in-memory state with the data stored in the persistent database.
Returns
| Type | Description |
|---|---|
null |
sync()
@classmethod
def sync() - > null
Updates the persistent database with the current in-memory state and flushes changes to disk.
Returns
| Type | Description |
|---|---|
null |
close()
@classmethod
def close() - > null
Closes the persistent database connection if it is currently open.
Returns
| Type | Description |
|---|---|
null |
save()
@classmethod
def save() - > null
Saves the current state to the database and closes the storage connection.
Returns
| Type | Description |
|---|---|
null |
db()
@classmethod
def db() - > shelve.DbfilenameShelf
Provides a cached connection to the persistent storage, opening it on first access.
Returns
| Type | Description |
|---|---|
shelve.DbfilenameShelf | The opened shelf database instance. |