ccproxy.scheduler.tasks¶
ccproxy.scheduler.tasks
¶
Base scheduled task classes and task implementations.
BaseScheduledTask
¶
BaseScheduledTask(
name,
interval_seconds,
enabled=True,
max_backoff_seconds=300.0,
jitter_factor=0.25,
)
Bases: ABC
Abstract base class for all scheduled tasks.
Provides common functionality for task lifecycle management, error handling, and exponential backoff for failed executions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Human-readable task name |
required |
interval_seconds
|
float
|
Interval between task executions in seconds |
required |
enabled
|
bool
|
Whether the task is enabled |
True
|
max_backoff_seconds
|
float
|
Maximum backoff delay for failed tasks |
300.0
|
jitter_factor
|
float
|
Jitter factor for backoff randomization (0.0-1.0) |
0.25
|
Source code in ccproxy/scheduler/tasks.py
run
abstractmethod
async
¶
Execute the scheduled task.
Returns:
Type | Description |
---|---|
bool
|
True if execution was successful, False otherwise |
setup
async
¶
Perform any setup required before task execution starts.
Called once when the task is first started. Override if needed. Default implementation does nothing.
Source code in ccproxy/scheduler/tasks.py
cleanup
async
¶
Perform any cleanup required after task execution stops.
Called once when the task is stopped. Override if needed. Default implementation does nothing.
Source code in ccproxy/scheduler/tasks.py
calculate_next_delay
¶
Calculate the delay before the next task execution.
Returns exponential backoff delay for failed tasks, or normal interval for successful tasks, with optional jitter.
Returns:
Type | Description |
---|---|
float
|
Delay in seconds before next execution |
Source code in ccproxy/scheduler/tasks.py
start
async
¶
Start the scheduled task execution loop.
Source code in ccproxy/scheduler/tasks.py
stop
async
¶
Stop the scheduled task execution loop.
Source code in ccproxy/scheduler/tasks.py
get_status
¶
Get current task status information.
Returns:
Type | Description |
---|---|
dict[str, Any]
|
Dictionary with task status details |
Source code in ccproxy/scheduler/tasks.py
PushgatewayTask
¶
Bases: BaseScheduledTask
Task for pushing metrics to Pushgateway periodically.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Task name |
required |
interval_seconds
|
float
|
Interval between pushgateway operations |
required |
enabled
|
bool
|
Whether task is enabled |
True
|
max_backoff_seconds
|
float
|
Maximum backoff delay for failures |
300.0
|
Source code in ccproxy/scheduler/tasks.py
setup
async
¶
Initialize metrics instance for pushgateway operations.
Source code in ccproxy/scheduler/tasks.py
run
async
¶
Execute pushgateway metrics push.
Source code in ccproxy/scheduler/tasks.py
StatsPrintingTask
¶
Bases: BaseScheduledTask
Task for printing stats summary periodically.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Task name |
required |
interval_seconds
|
float
|
Interval between stats printing |
required |
enabled
|
bool
|
Whether task is enabled |
True
|
Source code in ccproxy/scheduler/tasks.py
setup
async
¶
Initialize stats collector and metrics instances.
Source code in ccproxy/scheduler/tasks.py
run
async
¶
Execute stats printing.
Source code in ccproxy/scheduler/tasks.py
PricingCacheUpdateTask
¶
PricingCacheUpdateTask(
name,
interval_seconds,
enabled=True,
force_refresh_on_startup=False,
pricing_updater=None,
)
Bases: BaseScheduledTask
Task for updating pricing cache periodically.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Task name |
required |
interval_seconds
|
float
|
Interval between pricing updates |
required |
enabled
|
bool
|
Whether task is enabled |
True
|
force_refresh_on_startup
|
bool
|
Whether to force refresh on first run |
False
|
pricing_updater
|
Any | None
|
Injected pricing updater instance |
None
|
Source code in ccproxy/scheduler/tasks.py
setup
async
¶
Initialize pricing updater instance if not injected.
Source code in ccproxy/scheduler/tasks.py
run
async
¶
Execute pricing cache update.