feat: togglable continue on disapproval/timeout of approvals

This commit is contained in:
Ruben Fiszel
2024-08-14 17:24:21 +02:00
parent fbd9b87c0f
commit be90b3e219
2 changed files with 30 additions and 7 deletions
+27 -4
View File
@@ -1716,7 +1716,26 @@ async fn push_next_flow_job<R: rsmq_async::RsmqConnection + Send + Sync + Clone>
}
let is_disapproved = resumes.iter().find(|x| !x.approved);
if is_disapproved.is_none() && resume_messages.len() >= required_events as usize {
let can_be_resumed =
is_disapproved.is_none() && resume_messages.len() >= required_events as usize;
let disapproved_or_timeout_but_continue = !can_be_resumed
&& (is_disapproved.is_some()
|| !matches!(
&status_module,
FlowStatusModule::WaitingForPriorSteps { .. }
))
&& suspend.continue_on_disapprove_timeout.unwrap_or(false);
if can_be_resumed || disapproved_or_timeout_but_continue {
if disapproved_or_timeout_but_continue {
let js = if let Some(disapproved) = is_disapproved.as_ref() {
json!({"error": {"message": format!("Disapproved by {}", disapproved.approver.clone().unwrap_or_else( || "unknown".to_string())), "name": "SuspendedDisapproved"}})
} else {
json!({"error": {"message": "Timed out waiting to be resumed", "name": "SuspendedTimedOut"}})
};
resume_messages.push(to_raw_value(&js));
}
sqlx::query(
"UPDATE queue
SET flow_status = JSONB_SET(flow_status, ARRAY['modules', $1::TEXT, 'approvers'], $2)
@@ -1750,8 +1769,6 @@ async fn push_next_flow_job<R: rsmq_async::RsmqConnection + Send + Sync + Clone>
tx.commit().await?;
/* not enough messages to do this job, "park"/suspend until there are */
} else if suspend.continue_on_disapprove_timeout.unwrap_or(false) {
todo!()
} else if matches!(
&status_module,
FlowStatusModule::WaitingForPriorSteps { .. }
@@ -1790,7 +1807,13 @@ async fn push_next_flow_job<R: rsmq_async::RsmqConnection + Send + Sync + Clone>
let (logs, error_name) = if let Some(disapprover) = is_disapproved {
(
format!("Disapproved by {:?}", disapprover.approver),
format!(
"Disapproved by {}",
disapprover
.approver
.clone()
.unwrap_or_else(|| "unknown".to_string())
),
"SuspendedDisapproved",
)
} else {
@@ -119,11 +119,11 @@
{/if}
</Label>
<!-- <Toggle
<Toggle
options={{
right: 'Continue on disapproval/timeout',
rightTooltip:
'Instead of failing the flow, continue to the next step to be processed by a branchone. If any disapproval/timeout event is received, the resume payload will be an object containing an `error` field'
'Instead of failing the flow and bubbling up the error, continue to the next step which would allow to put a branchone right after to handle both cases separately. If any disapproval/timeout event is received, the resume payload will be similar to every error result in Winmdill, an object containing an `error` field which you can use to distinguish between approvals and disapproval/timeouts'
}}
checked={Boolean(flowModule.suspend?.continue_on_disapprove_timeout)}
disabled={!Boolean(flowModule.suspend)}
@@ -132,7 +132,7 @@
flowModule.suspend.continue_on_disapprove_timeout = e.detail
}
}}
/> -->
/>
</div>
{:else if suspendTabSelected === 'permissions'}
<div class="flex flex-col mt-4 gap-4">