Skip to content

Schedule sunrise/sunset events#15

Merged
johanflint merged 12 commits into
mainfrom
feature/schedule-sunset
Oct 27, 2025
Merged

Schedule sunrise/sunset events#15
johanflint merged 12 commits into
mainfrom
feature/schedule-sunset

Conversation

@johanflint

Copy link
Copy Markdown
Owner
  • Add Schedule as an abstraction over cron::Schedule with support for sunrise and sunset events
  • Sunrise/sunset times may have an offset specified in minutes
  • Add a builder to Context to make tests more readable
  • Use the local timezone instead of UTC in the scheduler

Introduces the `Schedule` enum to represent different scheduling options, including cron expressions and sunrise/sunset events.

Adds deserialization logic for the `Schedule` enum, allowing it to be parsed from JSON configurations. This enhances the flexibility of defining flow execution schedules.
Introduces a scheduling mechanism that supports cron expressions and solar events (sunrise/sunset) with offsets.

This allows for more flexible and dynamic trigger conditions.
Updates the Flow struct to use the Schedule enum instead of a String for representing schedules.
This change improves type safety and allows for more structured schedule definitions,
including cron expressions and sunrise/sunset based schedules.

Also, validates cron expressions during deserialization, preventing invalid schedules from being loaded.
Adds a Display implementation for the Schedule enum, making it easier to log and debug scheduled flows.
Moves the `Weekday` enum from the `flow_engine` module to the `domain` module to improve code organization and reusability.

This change centralizes the `Weekday` definition, making it accessible to other parts of the application that may need to work with weekdays.
The `ToWeekday` trait and its implementation for `chrono::DateTime`
were previously defined in `expression.rs`. This commit moves them to
a new `date_time_ext.rs` file within the `extensions` module. This
change promotes code reusability and maintains a cleaner structure.
Moves the `WeekdayCondition` enum from the `flow_engine` module to the `domain` module.

This change promotes better separation of concerns by defining `WeekdayCondition`
alongside other domain-specific types, enhancing code organization and reducing
dependencies within the `flow_engine`.
Moves the `Time` struct from the flow engine to the domain layer to promote code reuse and align with domain-driven design principles.
Refactors the Context struct to use a builder pattern for easier and more flexible initialization.

This change removes the direct `new` and `new_with_now` methods and introduces a `ContextBuilder` struct. This allows for optional parameters during context creation, improving code readability and maintainability.

The `execute_flow` and `execute_flows` functions are updated to use the new builder pattern.
Changes scheduler to use local time instead of UTC
when calculating upcoming sunset events. This ensures
schedules are triggered according to the user's timezone.
Updates the sunset schedule offset to use minutes instead of seconds.

This provides a more intuitive and practical way to configure the
desired offset for sunset events.
Allows schedules to be defined without a specific weekday.

This introduces an 'Any' weekday condition, enabling schedule
definitions that apply regardless of the day of the week. It also
handles cases where 'when' is missing in the schedule definition,
defaulting to the 'Any' condition.
@johanflint johanflint merged commit f60a2a8 into main Oct 27, 2025
6 checks passed
@johanflint johanflint deleted the feature/schedule-sunset branch October 27, 2025 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant