Skip to main content

apalis_sqlite/queries/
keep_alive.rs

1use apalis_core::worker::context::WorkerContext;
2use sqlx::Executor;
3
4use crate::config::Config;
5
6/// Send a keep-alive signal to the database to indicate that the worker is still active
7pub async fn keep_alive<'a, E>(
8    executor: E,
9    config: &Config,
10    worker: &WorkerContext,
11) -> Result<(), sqlx::Error>
12where
13    E: Executor<'a, Database = sqlx::Sqlite>,
14{
15    let worker = worker.name().to_owned();
16    let queue = config.queue.to_string();
17    let res = sqlx::query_file!("queries/backend/keep_alive.sql", worker, queue)
18        .execute(executor)
19        .await?;
20    if res.rows_affected() == 0 {
21        return Err(sqlx::Error::Io(std::io::Error::new(
22            std::io::ErrorKind::NotFound,
23            "WORKER_DOES_NOT_EXIST",
24        )));
25    }
26    Ok(())
27}