use alibi_core::{AuthContext, AuthResult, AuthSchema};
pub(crate) async fn run_notification(notification: impl Future<Output = AuthResult<()>>) {
if let Err(error) = notification.await {
tracing::error!(%error, "Failed to run background task");
}
}
pub(crate) async fn run_owned_notification(
context: &AuthContext<impl AuthSchema>,
notification: impl Future<Output = AuthResult<()>> + Send + 'static,
error_policy: alibi_core::AwaitedNotificationErrorPolicy,
) -> AuthResult<()> {
if let Some(handler) = &context.config.background_tasks {
let completion = alibi_core::start_background_task(async move {
run_notification(notification).await;
Ok(())
})
.await?;
if let Err(error) = handler.handle(completion) {
tracing::error!(%error, "Failed to observe background task");
}
} else {
match error_policy {
alibi_core::AwaitedNotificationErrorPolicy::Propagate => notification.await?,
alibi_core::AwaitedNotificationErrorPolicy::LogAndContinue => {
run_notification(notification).await;
}
}
}
Ok(())
}