use flashq::{FlashQ, PushOptions};
#[tokio::main]
async fn main() -> flashq::Result<()> {
let client = FlashQ::new();
client.connect().await?;
let id1 = client
.push(
"unique-demo",
serde_json::json!({"email": "user@example.com"}),
Some(PushOptions {
unique_key: Some("email:user@example.com".to_string()),
..Default::default()
}),
)
.await?;
println!("First push: job {id1}");
let result = client
.push(
"unique-demo",
serde_json::json!({"email": "user@example.com"}),
Some(PushOptions {
unique_key: Some("email:user@example.com".to_string()),
..Default::default()
}),
)
.await;
match result {
Ok(id2) => println!("Second push: job {id2} (same ID means deduplicated)"),
Err(e) => println!("Second push rejected (duplicate): {e}"),
}
let id3 = client
.push(
"unique-demo",
serde_json::json!({"order": "ORD-123"}),
Some(PushOptions {
job_id: Some("order-123".to_string()),
..Default::default()
}),
)
.await?;
println!("Custom ID push: job {id3}");
let found = client.get_job_by_custom_id("order-123").await?;
if let Some(jws) = found {
println!(
"Found by custom ID: job {} state={:?}",
jws.job.id, jws.state
);
}
client.close().await?;
Ok(())
}