Skip to content

Commit

Permalink
fix: fix manager log rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterPtato committed Jan 7, 2025
1 parent 3c6f8ec commit 1bffa14
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/infra/client/logs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{os::fd::AsRawFd, path::PathBuf};

use anyhow::*;
use chrono::{Datelike, Duration, TimeZone, Utc};
use chrono::{Datelike, Duration, TimeDelta, TimeZone, Utc};
use tokio::fs;

pub struct Logs {
Expand Down Expand Up @@ -40,6 +40,7 @@ impl Logs {
if self.next_rotation - now > Duration::seconds(5) {
tokio::time::sleep(
(self.next_rotation - now - Duration::seconds(5))
.max(TimeDelta::default())
.to_std()
.expect("bad duration"),
)
Expand Down
18 changes: 16 additions & 2 deletions packages/infra/client/manager/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ fn main() -> Result<()> {
init_tracing();

let init = { Runtime::new()?.block_on(init())? };
let mut first = true;

// Retry loop
loop {
let runtime = Builder::new_multi_thread().enable_all().build()?;

match runtime.block_on(run(init.clone())) {
match runtime.block_on(run(init.clone(), first)) {
Ok(_) => return Ok(()),
Err(err) => {
// Only restart if its a `RuntimeError`
Expand All @@ -58,6 +59,8 @@ fn main() -> Result<()> {
}
}

first = false;

std::thread::sleep(Duration::from_secs(2));
}
}
Expand Down Expand Up @@ -173,7 +176,18 @@ async fn init() -> Result<Init> {
})
}

async fn run(init: Init) -> Result<()> {
async fn run(init: Init, first: bool) -> Result<()> {
// We have to redirect logs here as well because the entire tokio runtime gets destroyed after a runtime
// error
if !first && init.config.client.logs.redirect_logs() {
pegboard_logs::Logs::new(
init.config.client.data_dir().join("logs"),
init.config.client.logs.retention(),
)
.start()
.await?;
}

// Start metrics server
let metrics_thread = tokio::spawn(metrics::run_standalone(init.config.client.metrics.port()));

Expand Down

0 comments on commit 1bffa14

Please sign in to comment.