pynenc.trigger.conditions.cron¶
Context for time-based conditions like cron schedules.
This module provides time-based trigger conditions, including cron schedule triggers, that allow tasks to be executed at specific times or intervals.
Module Contents¶
Classes¶
Context for time-based conditions like cron schedules. |
|
Condition based on a cron schedule. |
API¶
- class pynenc.trigger.conditions.cron.CronContext(*, timestamp: datetime.datetime | None = None, last_execution: datetime.datetime | None = None)[source]¶
Bases:
pynenc.trigger.conditions.ConditionContextContext for time-based conditions like cron schedules.
This class provides the context needed for evaluating time-based trigger conditions, including a check window in seconds and optional last execution time tracking.
Initialization
Create a time context with custom check window, timestamp, and optional last execution.
- Parameters:
check_window_seconds – Duration in seconds to consider a match after scheduled time
timestamp – Specific timestamp to use (primarily for testing), defaults to current time
last_execution – Timestamp of the previous execution, or None if never executed
- _to_json(app: pynenc.app.Pynenc) dict[str, Any][source]¶
Create a serializable representation of this time context.
- Parameters:
app – Pynenc application instance
- Returns:
Dictionary with serialized context data
- classmethod _from_json(data: dict[str, Any], app: pynenc.app.Pynenc) pynenc.trigger.conditions.cron.CronContext[source]¶
Create a CronContext from parsed JSON data.
- Parameters:
data – Dictionary with context data
app – Pynenc application instance
- Returns:
A new CronContext instance
- class pynenc.trigger.conditions.cron.CronCondition(cron_expression: str, check_window_seconds: int = 60)[source]¶
Bases:
pynenc.trigger.conditions.base.TriggerCondition[pynenc.trigger.conditions.cron.CronContext]Condition based on a cron schedule.
Triggers a task at times matching a specified cron expression.
Initialization
Create a cron-based trigger condition.
- Parameters:
cron_expression – Standard cron expression (e.g., “0 0 * * *” for daily at midnight)
- Raises:
ValueError – If the cron expression is invalid
- context_type: ClassVar[type[pynenc.trigger.conditions.cron.CronContext]]¶
None
- property condition_id: str¶
Generate a unique ID for this cron condition.
- Returns:
A string ID based on the cron expression
- _to_json(app: pynenc.app.Pynenc) dict[str, Any][source]¶
Create a serializable representation of this condition.
- Parameters:
app – Pynenc application instance
- Returns:
Dictionary with serialized condition data
- classmethod _from_json(data: dict[str, Any], app: pynenc.app.Pynenc) pynenc.trigger.conditions.cron.CronCondition[source]¶
Create a CronCondition from parsed JSON data.
- Parameters:
data – Dictionary with condition data
app – Pynenc application instance
- Returns:
A new CronCondition instance
- Raises:
ValueError – If the data is invalid for this condition type
- _is_satisfied_by(context: pynenc.trigger.conditions.cron.CronContext) bool[source]¶
Check if the current time matches the cron schedule.
A time matches when it is within the check window after a scheduled run time. For example, with a daily noon schedule (0 12 * * *), this checks if the timestamp is between noon and noon + check_window_seconds.
When context includes last_execution, this method also verifies that enough time has passed since the last execution according to the cron schedule.
- Parameters:
context – Time context with timestamp and check window
- Returns:
True if the timestamp falls within the check window after a scheduled run