pub fn enqueue_in<J: Serialize>(
ctx: &Ctx,
job: &J,
delay: Duration,
) -> impl Future<Output = Result<()>> + Send + use<J>Expand description
Sends job to the JOBS queue like enqueue, to run after delay.
The delay is whole seconds, 24 hours at most
(MAX_DELAY); for later work, enqueue from a
scheduled task or store the due time in D1. Costs the same Queues
operations as enqueue.
§Errors
Error::Internal (500) when delay is over
24 hours, plus every error of enqueue.
§Examples
use std::time::Duration;
use axum::extract::State;
use ocre::{Ctx, Result};
use serde::Serialize;
#[derive(Serialize)]
#[serde(rename_all = "snake_case")]
enum Job {
SendReminder { user_id: i64 },
}
async fn remind(State(ctx): State<Ctx>) -> Result<&'static str> {
let reminder = Job::SendReminder { user_id: 1 };
ocre::jobs::enqueue_in(&ctx, &reminder, Duration::from_secs(3600)).await?;
Ok("reminder set")
}