refactor workspace error handler

This commit is contained in:
Ruben Fiszel
2024-05-01 23:48:23 +02:00
parent 31f0199b80
commit ff3989e97f

View File

@@ -731,19 +731,17 @@ pub async fn add_completed_job<
}
}
#[cfg(feature = "enterprise")]
if !skip_downstream_error_handlers
&& matches!(queued_job.job_kind, JobKind::Flow | JobKind::Script)
&& queued_job.parent_job.is_none()
&& !success
{
let result = sanitize_result(result);
tracing::info!(
"Sending error of job {} to error handlers (if any)",
queued_job.id
);
if let Err(e) =
send_error_to_global_handler(rsmq.clone(), &queued_job, db, Json(&result)).await
{
if let Err(e) = send_error_to_global_handler(rsmq.clone(), &queued_job, db, result).await {
tracing::error!(
"Could not run global error handler for job {}: {}",
&queued_job.id,
@@ -756,7 +754,7 @@ pub async fn add_completed_job<
&queued_job,
canceled_by.is_some(),
db,
Json(&result),
result,
)
.await
{
@@ -960,7 +958,7 @@ pub async fn send_error_to_global_handler<
rsmq: Option<R>,
queued_job: &QueuedJob,
db: &Pool<Postgres>,
result: Json<&'a T>,
result: Json<&T>,
) -> Result<(), Error> {
if let Some(ref global_error_handler) = *GLOBAL_ERROR_HANDLER_PATH_IN_ADMINS_WORKSPACE {
let prefixed_global_error_handler_path = if global_error_handler.starts_with("script/")
@@ -970,11 +968,12 @@ pub async fn send_error_to_global_handler<
} else {
format!("script/{}", global_error_handler)
};
let result = sanitize_result(result);
run_error_handler(
rsmq,
queued_job,
db,
result,
Json(&result),
&prefixed_global_error_handler_path,
None,
true,
@@ -1036,12 +1035,13 @@ pub async fn send_error_to_workspace_handler<
let muted = ws_error_handler_muted.unwrap_or(false);
if !muted {
let result = sanitize_result(result);
tracing::info!("workspace error handled for job {}", &queued_job.id);
run_error_handler(
rsmq,
queued_job,
db,
result,
Json(&result),
&error_handler,
error_handler_extra_args,
false,
@@ -1171,6 +1171,7 @@ async fn apply_schedule_handlers<
let skip_downstream_error_handlers = schedule.ws_error_handler_muted;
if !success {
#[cfg(feature = "enterprise")]
if let Some(on_failure_path) = schedule.on_failure.clone() {
let times = schedule.on_failure_times.unwrap_or(1).max(1);
let exact = schedule.on_failure_exact.unwrap_or(false);
@@ -1240,6 +1241,7 @@ async fn apply_schedule_handlers<
}
}
} else {
#[cfg(feature = "enterprise")]
if let Some(on_recovery_path) = schedule.on_recovery.clone() {
let times = schedule.on_recovery_times.unwrap_or(1).max(1);
let past_jobs = sqlx::query_as!(