pub async fn atomic_enqueue<'e, E>(
executor: E,
cron_name: &str,
fire_time: DateTime<Utc>,
previous_enqueued_at: Option<DateTime<Utc>>,
) -> Result<Option<JobRow>, AwaError>where
E: PgExecutor<'e>,Expand description
Atomically mark a cron job as enqueued AND insert the resulting job.
Uses a single CTE so that both the UPDATE and INSERT happen in one atomic operation. If the process crashes mid-transaction, Postgres rolls back both. If another leader already claimed this fire time (last_enqueued_at no longer matches), the UPDATE matches 0 rows and the INSERT produces nothing.
Returns the inserted job row, or None if the fire was already claimed.