-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(workflows): fix listening traits
- Loading branch information
1 parent
7f75b56
commit c31f3c2
Showing
19 changed files
with
365 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use crate::{ | ||
ctx::WorkflowCtx, | ||
db::SignalRow, | ||
error::{WorkflowError, WorkflowResult}, | ||
}; | ||
|
||
/// Indirection struct to prevent invalid implementations of listen traits. | ||
pub struct ListenCtx<'a> { | ||
ctx: &'a mut WorkflowCtx, | ||
} | ||
|
||
impl<'a> ListenCtx<'a> { | ||
pub(crate) fn new(ctx: &'a mut WorkflowCtx) -> Self { | ||
ListenCtx { ctx } | ||
} | ||
|
||
/// Checks for a signal to this workflow with any of the given signal names. | ||
pub async fn listen_any(&self, signal_names: &[&'static str]) -> WorkflowResult<SignalRow> { | ||
// Fetch new pending signal | ||
let signal = self | ||
.ctx | ||
.db | ||
.pull_next_signal( | ||
self.ctx.workflow_id(), | ||
signal_names, | ||
self.ctx.full_location().as_ref(), | ||
) | ||
.await?; | ||
|
||
let Some(signal) = signal else { | ||
return Err(WorkflowError::NoSignalFound(Box::from(signal_names))); | ||
}; | ||
|
||
tracing::info!( | ||
workflow_name=%self.ctx.name(), | ||
workflow_id=%self.ctx.workflow_id(), | ||
signal_id=%signal.signal_id, | ||
signal_name=%signal.signal_name, | ||
"signal received", | ||
); | ||
|
||
Ok(signal) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.