Polaroid
Record event snapshots.
Attributes
| Attribute | Type | Description |
|---|---|---|
| timer | [Timer](../../worker/components/timer.md?sid=celery_worker_components_timer) = null | The 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_after | boolean = false | Boolean 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
| Name | Type | Description |
|---|---|---|
| state | Any | The state object to be monitored or captured. |
| freq | float = 1.0 | The frequency at which snapshots are captured. |
| maxrate | Optional[str] = null | The maximum rate of snapshots allowed, converted to a TokenBucket if provided. |
| cleanup_freq | float = 3600.0 | The frequency at which the cleanup process is triggered. |
| timer | Optional[[Timer](../../worker/components/timer.md?sid=celery_worker_components_timer)] = null | The timer instance used to schedule recurring tasks. |
| app | Optional[Any] = null | The 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
| Type | Description |
|---|---|
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
| Name | Type | Description |
|---|---|---|
| state | any | The current state object being captured during the shutter event |
Returns
| Type | Description |
|---|---|
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
| Type | Description |
|---|---|
null |
cleanup()
@classmethod
def cleanup() - > null
Triggers the cleanup signal and executes the on_cleanup hook to perform periodic maintenance on the state.
Returns
| Type | Description |
|---|---|
null |
shutter()
@classmethod
def shutter() - > null
Sends the shutter signal and executes the on_shutter hook if the configured rate limit allows.
Returns
| Type | Description |
|---|---|
null |
capture()
@classmethod
def capture() - > null
Freezes the current state to safely execute the shutter logic, optionally clearing the state afterward.
Returns
| Type | Description |
|---|---|
null |
cancel()
@classmethod
def cancel() - > null
Cancels all scheduled timer tasks for capture and cleanup, ensuring no further periodic events are triggered.
Returns
| Type | Description |
|---|---|
null |