-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathweb.rs
More file actions
60 lines (53 loc) · 1.48 KB
/
web.rs
File metadata and controls
60 lines (53 loc) · 1.48 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
use anyhow::Context as _;
use clap::Parser;
use tracing::instrument;
use wtransport::{ClientConfig, Endpoint};
pub const DEFAULT_ADDR: &str = "https://localhost:4433";
/// WebTransport transport
#[derive(Parser, Debug)]
pub enum Command {
Run(RunArgs),
}
/// Run a command component
#[derive(Parser, Debug)]
pub struct RunArgs {
/// Invocation timeout
#[arg(long, default_value = crate::DEFAULT_TIMEOUT)]
timeout: humantime::Duration,
/// Address to send import invocations to
#[arg(long, default_value = DEFAULT_ADDR)]
import: String,
/// Path or URL to Wasm command component
workload: String,
}
#[instrument(level = "trace", ret(level = "trace"))]
pub async fn handle_run(
RunArgs {
timeout,
import,
ref workload,
}: RunArgs,
) -> anyhow::Result<()> {
let ep = Endpoint::client(ClientConfig::default())
.context("failed to create WebTransport endpoint")?;
// TODO: Allow TLS configuration via runtime flags
// TODO: Support WebPKI
let conn = ep
.connect(import)
.await
.context("failed to connect using WebTransport")?;
crate::handle_run(
wrpc_transport_web::Client::from(conn),
(),
*timeout,
workload,
)
.await
}
#[instrument(level = "trace", skip_all, ret(level = "trace"))]
pub async fn run(cmd: Command) -> anyhow::Result<()> {
match cmd {
Command::Run(args) => handle_run(args).await,
// TODO: Implement serving
}
}