Skip to content

Support sleep node in flows#13

Merged
johanflint merged 10 commits into
mainfrom
feature/wait-node
Oct 20, 2025
Merged

Support sleep node in flows#13
johanflint merged 10 commits into
mainfrom
feature/wait-node

Conversation

@johanflint

Copy link
Copy Markdown
Owner
  • Add a sleep node to allow a flow to delay execution for the configured amount of time
  • Support scheduling a job to be executed only once
  • Add id to Flow
  • Add flow registry instead of passing flows around
  • Update dependencies

Enables pausing execution within a flow for a specified duration.

This introduces a new `Sleep` node type in the flow engine, allowing for timed delays during flow execution. The duration is specified in the flow definition using human-readable format, leveraging the `humantime-serde` crate for easy parsing.
Introduces the ability to schedule flows to continue execution
after a specified duration when encountering a sleep node. This
is achieved by sending a `SchedulerCommand::ScheduleOnce` to the
scheduler, which then triggers the flow execution to resume at the
designated node after the delay.

This change also modifies the store listener and the main function to
pass the scheduler transmitter to the `execute_flows` function,
allowing scheduled executions from reactive flows.
Moves the scheduler module from its own directory into the flow_engine directory.

This change improves project organization and reflects that the scheduler is closely related and used by the flow engine. It also ensures that the flow engine has access to scheduling capabilities.

This change also updates references to the scheduler in other modules.
This commit introduces an `id` field to the `Flow` struct, enabling unique identification of flows.

The `Flow::new` function now requires an `id` parameter, which is stored within the `Flow` struct.

The flow loader and tests are updated to use the new `id` field.
Adds a `FlowRegistry` to manage and retrieve flows, replacing direct vector access.
This change improves flow organization and lookup efficiency, especially for scheduled flows.

The scheduler now uses the registry to fetch flows by id, and the store listener uses it to access reactive flows.
This centralizes flow management and reduces code duplication.
Addresses issues where spawned tasks were incorrectly consuming variables.

By cloning the `duration` field from the `Sleep` struct is unnecesary because `duration` implements the `Copy` trait and removing unnecessary clones of tx channels, it ensures that ownership is properly managed.
Adds the ability to execute flows starting from a specified node, rather than always from the beginning.
This enhances flexibility and allows resuming flows from interruption points.

Introduces the `execute_flow` function to facilitate execution from a specific node.
Refactors the `execute_flows` function and the flow engine to support this new functionality.
Adds logging to aid in debugging and monitoring flow execution.

Also moves command dispatching to its own function to remove duplication.
Updates dependencies to their latest versions.

Removes some unnecessary dependencies, improving the project's dependency footprint.
@johanflint johanflint merged commit 5fbd914 into main Oct 20, 2025
6 checks passed
@johanflint johanflint deleted the feature/wait-node branch October 20, 2025 09:57
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