style: cargo fmt --all

This commit is contained in:
2026-05-31 05:31:42 +02:00
parent 4b31a0f74b
commit c2ebca0da0
138 changed files with 2422 additions and 1164 deletions

View File

@@ -1,12 +1,14 @@
use crate::job::Job;
use async_trait::async_trait;
use tracing::info;
use crate::job::Job;
pub struct ExampleJob;
#[async_trait]
impl Job for ExampleJob {
fn name(&self) -> &str { "example" }
fn name(&self) -> &str {
"example"
}
async fn run(&self) -> anyhow::Result<()> {
info!("example job ran — replace with real work");
Ok(())

View File

@@ -14,8 +14,7 @@ use runner::JobRunner;
async fn main() -> anyhow::Result<()> {
tracing_subscriber::fmt()
.with_env_filter(
tracing_subscriber::EnvFilter::from_default_env()
.add_directive("worker=info".parse()?),
tracing_subscriber::EnvFilter::from_default_env().add_directive("worker=info".parse()?),
)
.init();

View File

@@ -1,14 +1,16 @@
use crate::job::Job;
use std::sync::Arc;
use std::time::Duration;
use tracing::{error, info};
use crate::job::Job;
pub struct JobRunner {
jobs: Vec<(Arc<dyn Job>, Duration)>,
}
impl JobRunner {
pub fn new() -> Self { Self { jobs: vec![] } }
pub fn new() -> Self {
Self { jobs: vec![] }
}
pub fn register(mut self, job: Arc<dyn Job>, interval: Duration) -> Self {
self.jobs.push((job, interval));
@@ -16,19 +18,29 @@ impl JobRunner {
}
pub async fn run(self) {
let handles: Vec<_> = self.jobs.into_iter().map(|(job, interval)| {
tokio::spawn(async move {
loop {
info!(job = job.name(), "running job");
if let Err(e) = job.run().await {
error!(job = job.name(), error = %e, "job failed");
let handles: Vec<_> = self
.jobs
.into_iter()
.map(|(job, interval)| {
tokio::spawn(async move {
loop {
info!(job = job.name(), "running job");
if let Err(e) = job.run().await {
error!(job = job.name(), error = %e, "job failed");
}
tokio::time::sleep(interval).await;
}
tokio::time::sleep(interval).await;
}
})
})
}).collect();
for handle in handles { let _ = handle.await; }
.collect();
for handle in handles {
let _ = handle.await;
}
}
}
impl Default for JobRunner { fn default() -> Self { Self::new() } }
impl Default for JobRunner {
fn default() -> Self {
Self::new()
}
}