MCPcopy Create free account
hub / github.com/Dstack-TEE/dstack / async_main

Function async_main

supervisor/src/main.rs:118–161  ·  view source on GitHub ↗
(args: Args)

Source from the content-addressed store, hash-verified

116
117#[tokio::main]
118async fn async_main(args: Args) -> Result<()> {
119 let mut figment = load_config_figment(args.config.as_deref());
120 if let Some(uds) = args.uds {
121 mk_parents(&uds)?;
122 if args.remove_existing_uds {
123 fs_err::remove_file(&uds).ok();
124 }
125 figment = figment.join(("address", format!("unix:{uds}")));
126 } else if let Some(address) = args.address {
127 figment = figment.join(("address", address));
128 }
129 if let Some(port) = args.port {
130 figment = figment.join(("port", port));
131 }
132 let rocket = web_api::rocket(figment);
133 let rocket = rocket.attach(AdHoc::on_response("Add app version header", |_req, res| {
134 Box::pin(async move {
135 res.set_raw_header("X-App-Version", app_version());
136 })
137 }));
138 let ignite = rocket
139 .ignite()
140 .await
141 .map_err(|err| anyhow!("{err:?}"))
142 .context("Failed to ignite rocket")?;
143 let endpoint = DefaultListener::bind_endpoint(&ignite)
144 .map_err(|err| anyhow!("{err:?}"))
145 .context("Failed to get endpoint")?;
146 let listener = DefaultListener::bind(&ignite)
147 .await
148 .map_err(|err| anyhow!("{err:?}"))
149 .context(format!("Failed to bind on {endpoint}"))?;
150 if let Some(pid_file) = &args.pid_file {
151 mk_parents(pid_file)?;
152 let pid = std::process::id();
153 fs_err::write(pid_file, pid.to_string()).context("Failed to write pid file")?;
154 }
155 ignite
156 .launch_on(listener)
157 .await
158 .map_err(|err| anyhow!("{err:?}"))
159 .context("Failed to launch rocket")?;
160 Ok(())
161}
162
163fn mk_parents(path: impl AsRef<Path>) -> Result<()> {
164 let path = path.as_ref();

Callers 1

mainFunction · 0.85

Calls 4

mk_parentsFunction · 0.85
rocketFunction · 0.85
load_config_figmentFunction · 0.70
app_versionFunction · 0.70

Tested by

no test coverage detected