|
@@ -302,6 +302,7 @@ pub async fn run(
|
|
|
token: Option<String>,
|
|
token: Option<String>,
|
|
|
open: bool,
|
|
open: bool,
|
|
|
insecure: bool,
|
|
insecure: bool,
|
|
|
|
|
+ repo_sync_interval: u32,
|
|
|
) -> anyhow::Result<()> {
|
|
) -> anyhow::Result<()> {
|
|
|
let addr: SocketAddr = format!("{bind}:{port}").parse()?;
|
|
let addr: SocketAddr = format!("{bind}:{port}").parse()?;
|
|
|
if !is_loopback(addr) && token.is_none() && !insecure {
|
|
if !is_loopback(addr) && token.is_none() && !insecure {
|
|
@@ -315,6 +316,7 @@ pub async fn run(
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
let (tx, _) = broadcast::channel(BUS_CAP);
|
|
let (tx, _) = broadcast::channel(BUS_CAP);
|
|
|
|
|
+ let cfg = config.clone(); // for the background recipe-repo re-sync
|
|
|
let app = AppState {
|
|
let app = AppState {
|
|
|
config: Arc::new(config),
|
|
config: Arc::new(config),
|
|
|
bus: tx,
|
|
bus: tx,
|
|
@@ -326,6 +328,25 @@ pub async fn run(
|
|
|
};
|
|
};
|
|
|
jobs::load(&app); // history survives restarts; in-flight jobs -> failed
|
|
jobs::load(&app); // history survives restarts; in-flight jobs -> failed
|
|
|
|
|
|
|
|
|
|
+ // Background recipe-repo re-sync (the initial sync already ran at command
|
|
|
|
|
+ // start): keeps the dashboard's recipe view fresh without a restart.
|
|
|
|
|
+ if repo_sync_interval > 0 {
|
|
|
|
|
+ let minutes = repo_sync_interval;
|
|
|
|
|
+ tokio::spawn(async move {
|
|
|
|
|
+ loop {
|
|
|
|
|
+ tokio::time::sleep(Duration::from_secs(minutes as u64 * 60)).await;
|
|
|
|
|
+ let roots = crate::recipe_repos::sync_recipe_repos(&cfg).await;
|
|
|
|
|
+ tracing::info!(
|
|
|
|
|
+ "{}",
|
|
|
|
|
+ fluent_i18n::t!("recipe-repo-watch", {
|
|
|
|
|
+ "n" => roots.len(),
|
|
|
|
|
+ "interval" => minutes
|
|
|
|
|
+ })
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
tokio::spawn(supervisor(app.clone()));
|
|
tokio::spawn(supervisor(app.clone()));
|
|
|
let listener = tokio::net::TcpListener::bind(addr).await?;
|
|
let listener = tokio::net::TcpListener::bind(addr).await?;
|
|
|
if open {
|
|
if open {
|