use apalis_libsql::LibsqlStorage;
use libsql::Builder;
use serde::{Deserialize, Serialize};
use std::env;
#[derive(Debug, Clone, Serialize, Deserialize)]
struct Notification {
user_id: String,
message: String,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let auth_token =
env::var("TURSO_AUTH_TOKEN").expect("TURSO_AUTH_TOKEN environment variable must be set");
let database_url = env::var("TURSO_DATABASE_URL")
.expect("TURSO_DATABASE_URL environment variable must be set");
println!("Connecting to Turso Cloud...");
let db = Builder::new_remote(database_url, auth_token)
.build()
.await?;
let db: &'static _ = Box::leak(Box::new(db));
let storage = LibsqlStorage::<Notification, ()>::new(db);
storage.setup().await?;
println!("Database setup complete!");
use apalis_core::backend::TaskSink;
let mut storage = storage;
storage
.push(Notification {
user_id: "user123".to_string(),
message: "Welcome to our service!".to_string(),
})
.await?;
storage
.push(Notification {
user_id: "user456".to_string(),
message: "Your order has been processed.".to_string(),
})
.await?;
println!("Tasks pushed to Turso Cloud!");
println!("The embedded replica will sync with the cloud automatically.");
Ok(())
}