Skip to main content

apalis_postgres/queries/
handle_result.rs

1use apalis_core::backend::TaskResult;
2use sqlx::Executor;
3
4use crate::error::Error;
5
6/// Serialized result payload including the current attempt and status
7pub type Payload = TaskResult<serde_json::Value>;
8
9/// Ack multiple tasks, given a worker
10pub async fn handle_results<E>(
11    executor: &mut E,
12    results: &[&Payload],
13    worker_id: &str,
14) -> Result<u64, Error>
15where
16    for<'e> &'e mut E: Executor<'e, Database = sqlx::Postgres>,
17{
18    let payload_json = serde_json::to_value(results).map_err(Error::JsonError)?;
19
20    let result = sqlx::query_file!("queries/task/handle_result.sql", payload_json, worker_id)
21        .execute(executor)
22        .await?;
23
24    Ok(result.rows_affected())
25}