Merge pull request #16 from DeterminateSystems/http-startup-notification
Send startup notification via HTTP
This commit is contained in:
commit
75b1450fdf
|
@ -23,7 +23,6 @@ use std::collections::HashSet;
|
||||||
use std::fs::{self, create_dir_all, OpenOptions};
|
use std::fs::{self, create_dir_all, OpenOptions};
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::os::fd::FromRawFd;
|
|
||||||
use std::os::unix::fs::PermissionsExt;
|
use std::os::unix::fs::PermissionsExt;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
@ -103,9 +102,9 @@ struct Args {
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
use_flakehub: bool,
|
use_flakehub: bool,
|
||||||
|
|
||||||
/// File descriptor on which to send startup notification.
|
/// URL to which to post startup notification.
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
notify_fd: Option<i32>,
|
startup_notification_url: Option<reqwest::Url>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The global server state.
|
/// The global server state.
|
||||||
|
@ -300,9 +299,27 @@ async fn main_cli() {
|
||||||
|
|
||||||
tracing::info!("Listening on {}", args.listen);
|
tracing::info!("Listening on {}", args.listen);
|
||||||
|
|
||||||
if let Some(notify_fd) = args.notify_fd {
|
if let Some(startup_notification_url) = args.startup_notification_url {
|
||||||
let mut f = unsafe { std::fs::File::from_raw_fd(notify_fd) };
|
let response = reqwest::Client::new()
|
||||||
writeln!(&mut f, "INIT").unwrap();
|
.post(startup_notification_url)
|
||||||
|
.header(reqwest::header::CONTENT_TYPE, "application/json")
|
||||||
|
.body("{}")
|
||||||
|
.send()
|
||||||
|
.await;
|
||||||
|
match response {
|
||||||
|
Ok(response) => {
|
||||||
|
if !response.status().is_success() {
|
||||||
|
panic!(
|
||||||
|
"Startup notification returned an error: {}\n{}",
|
||||||
|
response.status(),
|
||||||
|
response.text().await.unwrap_or_else(|_| "".to_owned())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
panic!("Startup notification failed: {}", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let ret = axum::Server::bind(&args.listen)
|
let ret = axum::Server::bind(&args.listen)
|
||||||
|
@ -339,7 +356,7 @@ async fn post_build_hook(out_paths: &str) {
|
||||||
|
|
||||||
let response = reqwest::Client::new()
|
let response = reqwest::Client::new()
|
||||||
.post(format!("http://{}/api/enqueue-paths", &args.server))
|
.post(format!("http://{}/api/enqueue-paths", &args.server))
|
||||||
.header("Content-Type", "application/json")
|
.header(reqwest::header::CONTENT_TYPE, "application/json")
|
||||||
.body(serde_json::to_string(&request).unwrap())
|
.body(serde_json::to_string(&request).unwrap())
|
||||||
.send()
|
.send()
|
||||||
.await;
|
.await;
|
||||||
|
|
Loading…
Reference in a new issue