akkudoktoreos.server.retentionmanager.JobState
- class akkudoktoreos.server.retentionmanager.JobState(name: str, func: Callable[[], None] | Callable[[], Coroutine[Any, Any, None]], interval_attr: str, fallback_interval: float, config_getter: Callable[[str], Any], on_exception: Callable[[Exception], None] | Callable[[Exception], Coroutine[Any, Any, None]] | None = None, last_run_at: float = 0.0, last_duration: float = 0.0, last_error: str | None = None, run_count: int = 0, is_running: bool = False)
Bases:
objectRuntime state tracked for a single managed job.
- name
Unique human-readable job name used in logs and metrics.
- Type:
str
- func
The maintenance callable. Must accept no arguments.
- interval_attr
Key passed to
config_getterto retrieve the interval in seconds for this job.- Type:
str
- fallback_interval
Interval in seconds used when the key is not found or returns zero.
- Type:
float
- config_getter
Callable that accepts a string key and returns the corresponding configuration value. Invoked with
interval_attrto obtain the interval in seconds.- Type:
Callable[[str], Any]
- on_exception
Optional callable invoked with the raised exception whenever
funcfails. May be sync or async.
- last_run_at
Monotonic timestamp of the last completed run;
0.0means never run.- Type:
float
- last_duration
How long the last run took, in seconds.
- Type:
float
- last_error
String representation of the last exception, or
Noneif the last run succeeded.- Type:
str | None
- run_count
Total number of completed runs (successful or not).
- Type:
int
- is_running
Truewhile the job coroutine is currently executing.- Type:
bool
- __init__(name: str, func: Callable[[], None] | Callable[[], Coroutine[Any, Any, None]], interval_attr: str, fallback_interval: float, config_getter: Callable[[str], Any], on_exception: Callable[[Exception], None] | Callable[[Exception], Coroutine[Any, Any, None]] | None = None, last_run_at: float = 0.0, last_duration: float = 0.0, last_error: str | None = None, run_count: int = 0, is_running: bool = False) None
Methods
__init__(name, func, interval_attr, ...[, ...])interval()Retrieve the current interval by calling
config_getterwithinterval_attr.is_due()Check whether enough time has elapsed since the last run to execute this job again.
summary()Build a serialisable snapshot of the job's current state.
Attributes
- name: str
- interval_attr: str
- fallback_interval: float
- config_getter: Callable[[str], Any]
- on_exception: Callable[[Exception], None] | Callable[[Exception], Coroutine[Any, Any, None]] | None = None
- last_run_at: float = 0.0
- last_duration: float = 0.0
- run_count: int = 0
- is_running: bool = False
- interval() float | None
Retrieve the current interval by calling
config_getterwithinterval_attr.Returns
Nonewhen the config value isNone, which signals that the job is disabled and must never fire. Falls back tofallback_intervalwhen the key is not found.- Returns:
The interval in seconds, or
Noneif the job is disabled.
- is_due() bool
Check whether enough time has elapsed since the last run to execute this job again.
Returns
Falseimmediately when interval returnsNone(job is disabled), so a disabled job never fires regardless of when it last ran.- Returns:
Trueif the job should be executed on this tick,Falseotherwise.
- summary() dict
Build a serialisable snapshot of the job’s current state.
- Returns:
A dictionary suitable for JSON serialisation, containing the job name, interval key, last run timestamp, last duration, last error, run count, and whether the job is currently running.
- __init__(name: str, func: Callable[[], None] | Callable[[], Coroutine[Any, Any, None]], interval_attr: str, fallback_interval: float, config_getter: Callable[[str], Any], on_exception: Callable[[Exception], None] | Callable[[Exception], Coroutine[Any, Any, None]] | None = None, last_run_at: float = 0.0, last_duration: float = 0.0, last_error: str | None = None, run_count: int = 0, is_running: bool = False) None