1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use vyuh::{Data, bundles, tasks::TaskOutcome};
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
struct EmailJob {
to: String,
subject: String,
}
#[bundles::task(name = "send_email")]
async fn send_email(input: Data<EmailJob>) -> TaskOutcome {
TaskOutcome::complete(&format!("sent {} to {}", input.subject, input.to)).unwrap()
}
fn app_bundle() -> bundles::Bundle {
bundles::bundle! {
send_email,
}
}
#[tokio::main]
async fn main() {
let _bundle = app_bundle();
// With a built Site:
// site.tasks().submit(EmailJob {
// to: "user@example.com".into(),
// subject: "Welcome".into(),
// }).await?;
//
// site.tasks()
// .submit_with(
// EmailJob {
// to: "user@example.com".into(),
// subject: "Welcome".into(),
// },
// vyuh::tasks::TaskOptions {
// initial_delay: Some(std::time::Duration::from_secs(300)),
// retry_delay: Some(std::time::Duration::from_secs(60)),
// lease_duration: Some(std::time::Duration::from_secs(900)),
// max_attempts: Some(5),
// identity: Some("welcome:user@example.com".into()),
// ..vyuh::tasks::TaskOptions::default()
// },
// )
// .await?;
}