Skip to content

How to run a delayed Job #168

Answered by geofmureithi
dzvon asked this question in Q&A
Discussion options

You must be logged in to vote

You should be able to use schedule and chrono.

Utc::now() + chrono::Duration::seconds(i),

async fn produce_emails(storage: &SqliteStorage<Email>) -> Result<()> {
let mut storage = storage.clone();
for i in 0..2 {
storage
.schedule(
Email {
to: format!("test{i}@example.com"),
text: "Test background job from apalis".to_string(),
subject: "Background email job".to_string(),
},
Utc::now() + chrono::Duration::seconds(i),
)
.await?;
}
Ok(())
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by geofmureithi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #167 on September 14, 2023 10:30.