Skip to main content

Polaroid

Record event snapshots.

Attributes

AttributeTypeDescription
timer[Timer](../../worker/components/timer.md?sid=celery_worker_components_timer) = nullThe timer instance used to schedule periodic snapshot and cleanup tasks.
shutter_signal[Signal](../../utils/dispatch/signal/signal.md?sid=celery_utils_dispatch_signal_signal) = Signal(name='shutter_signal', providing_args={'state'})Signal dispatched when a snapshot is captured, providing the current state to receivers.
cleanup_signal[Signal](../../utils/dispatch/signal/signal.md?sid=celery_utils_dispatch_signal_signal) = Signal(name='cleanup_signal')Signal dispatched during the periodic cleanup process to notify listeners to purge old data.
clear_afterboolean = falseBoolean flag determining whether the state should be cleared after a snapshot is taken.

Constructor

Signature

def Polaroid(
state: Any,
freq: float = 1.0,
maxrate: Optional[str] = null,
cleanup_freq: float = 3600.0,
timer: Optional[[Timer](../../worker/components/timer.md?sid=celery_worker_components_timer)] = null,
app: Optional[Any] = null
) - > null

Parameters

NameTypeDescription
stateAnyThe state object to be monitored or captured.
freqfloat = 1.0The frequency at which snapshots are captured.
maxrateOptional[str] = nullThe maximum rate of snapshots allowed, converted to a TokenBucket if provided.
cleanup_freqfloat = 3600.0The frequency at which the cleanup process is triggered.
timerOptional[[Timer](../../worker/components/timer.md?sid=celery_worker_components_timer)] = nullThe timer instance used to schedule recurring tasks.
appOptional[Any] = nullThe application instance associated with this recorder.

Methods


install()

@classmethod
def install() - > null

Schedules the periodic execution of snapshot capture and cleanup tasks using the configured timer.

Returns

TypeDescription
null

on_shutter()

@classmethod
def on_shutter(
state: any
) - > null

Hook method called when the shutter signal is triggered; intended to be overridden by subclasses to handle state snapshots.

Parameters

NameTypeDescription
stateanyThe current state object being captured during the shutter event

Returns

TypeDescription
null

on_cleanup()

@classmethod
def on_cleanup() - > null

Hook method called during the cleanup cycle; intended to be overridden by subclasses to perform custom maintenance tasks.

Returns

TypeDescription
null

cleanup()

@classmethod
def cleanup() - > null

Triggers the cleanup signal and executes the on_cleanup hook to perform periodic maintenance on the state.

Returns

TypeDescription
null

shutter()

@classmethod
def shutter() - > null

Sends the shutter signal and executes the on_shutter hook if the configured rate limit allows.

Returns

TypeDescription
null

capture()

@classmethod
def capture() - > null

Freezes the current state to safely execute the shutter logic, optionally clearing the state afterward.

Returns

TypeDescription
null

cancel()

@classmethod
def cancel() - > null

Cancels all scheduled timer tasks for capture and cleanup, ensuring no further periodic events are triggered.

Returns

TypeDescription
null