Skip to main content

flowrlib/
submission_handler.rs

1use flowcore::errors::Result;
2#[cfg(feature = "metrics")]
3use flowcore::model::metrics::Metrics;
4use flowcore::model::submission::Submission;
5
6use crate::run_state::RunState;
7
8/// Programs that wish to submit a flow for execution via a
9/// [Submission][flowcore::model::submission::Submission] and
10/// then track it's execution (such as a CLI or a UI) should implement this trait
11pub trait SubmissionHandler {
12    /// Execution of the flow is starting
13    ///
14    /// # Errors
15    ///
16    /// Returns an error if the message corresponding to the flow is starting cannot be sent
17    fn flow_execution_starting(&mut self) -> Result<()>;
18
19    /// The [Coordinator][crate::coordinator::Coordinator] executing the flow periodically
20    /// will check if there has been a request to enter the debugger.
21    ///
22    /// # Errors
23    ///
24    /// Returns an error if the request to check if debugger entry is required fails
25    #[cfg(feature = "debugger")]
26    fn should_enter_debugger(&mut self) -> Result<bool>;
27
28    /// The [Coordinator][crate::coordinator::Coordinator] informs the submitter that the execution
29    /// of the flow has ended
30    ///
31    /// # Errors
32    ///
33    /// Returns an error if the message corresponding to the flow has ended cannot be sent
34    fn flow_execution_ended(
35        &mut self,
36        state: &RunState,
37        #[cfg(feature = "metrics")] metrics: Metrics,
38    ) -> Result<()>;
39
40    /// The [Coordinator][crate::coordinator::Coordinator] wait for a
41    /// [Submission][flowcore::model::submission::Submission] to be sent for execution
42    ///
43    /// # Errors
44    ///
45    /// Returns an error if there is an error while waiting for a submission (usually networking9
46    ///
47    fn wait_for_submission(&mut self) -> Result<Option<Submission>>;
48
49    /// The [Coordinator][crate::coordinator::Coordinator] periodically checks if the client
50    /// has requested that execution be stopped.
51    ///
52    /// # Errors
53    ///
54    /// Returns an error if the check fails
55    fn should_stop(&mut self) -> Result<bool> {
56        Ok(false)
57    }
58
59    /// Called by the [Coordinator][crate::coordinator::Coordinator] after jobs are retired,
60    /// with the total number of jobs created so far. Default implementation is a no-op.
61    fn jobs_created(&mut self, _count: usize) {}
62
63    /// The [Coordinator][crate::coordinator::Coordinator] is about to exit
64    ///
65    /// # Errors
66    ///
67    /// Will return `Err` if this cannot be communicated to the client
68    fn coordinator_is_exiting(&mut self, result: Result<()>) -> Result<()>;
69}