use std::time::Duration;
use flashq::{FlashQ, PushOptions};
#[tokio::main]
async fn main() -> flashq::Result<()> {
let client = FlashQ::new();
client.connect().await?;
let id = client
.push(
"scheduled",
serde_json::json!({"action": "send-reminder"}),
Some(PushOptions {
delay: Some(2000), ..Default::default()
}),
)
.await?;
println!("Pushed delayed job: {id}");
let state = client.get_state(id).await?;
println!("State right after push: {:?}", state);
let job = client
.pull("scheduled", Some(Duration::from_secs(1)))
.await?;
println!("Pull before delay: {:?}", job.is_some());
println!("Waiting 2 seconds for job to become ready...");
tokio::time::sleep(Duration::from_secs(2)).await;
if let Some(job) = client
.pull("scheduled", Some(Duration::from_secs(3)))
.await?
{
println!("Pulled delayed job {}: {:?}", job.id, job.data);
client.ack(job.id, None).await?;
}
client.close().await?;
Ok(())
}