Skip to main content

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

AttributeTypeDescription
storagemodule = shelveThe storage module or interface used to open the persistent database file, defaulting to the standard library shelve module.
protocolint = pickle_protocolThe pickle protocol version used for serializing and deserializing the persistent state data.
compresscallable = zlib.compressThe compression function used to reduce the size of the revoked task data before it is stored in the database.
decompresscallable = zlib.decompressThe 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

NameTypeDescription
stateAnyThe worker state object containing revoked tasks.
filenamestrThe path to the database file used for persistence.
clockAny = NoneAn 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

TypeDescription
shelve.DbfilenameShelfA 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

TypeDescription
null

sync()

@classmethod
def sync() - > null

Updates the persistent database with the current in-memory state and flushes changes to disk.

Returns

TypeDescription
null

close()

@classmethod
def close() - > null

Closes the persistent database connection if it is currently open.

Returns

TypeDescription
null

save()

@classmethod
def save() - > null

Saves the current state to the database and closes the storage connection.

Returns

TypeDescription
null

db()

@classmethod
def db() - > shelve.DbfilenameShelf

Provides a cached connection to the persistent storage, opening it on first access.

Returns

TypeDescription
shelve.DbfilenameShelfThe opened shelf database instance.