aboutsummaryrefslogtreecommitdiff
path: root/src/util/background/mod.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2022-06-21 17:18:16 +0200
committerAlex Auvolat <alex@adnab.me>2022-06-21 17:18:16 +0200
commit10c886111e304a53be24b29194f2127d91121929 (patch)
treebd61e98beeccfe338c1ae41a8c1322493f618dd2 /src/util/background/mod.rs
parent14337d2a561887b94ea165727dd49263717cb478 (diff)
downloadgarage-10c886111e304a53be24b29194f2127d91121929.tar.gz
garage-10c886111e304a53be24b29194f2127d91121929.zip
Rename things, garage worker list cmd
Diffstat (limited to 'src/util/background/mod.rs')
-rw-r--r--src/util/background/mod.rs25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/util/background/mod.rs b/src/util/background/mod.rs
index c06e2225..92090a1a 100644
--- a/src/util/background/mod.rs
+++ b/src/util/background/mod.rs
@@ -4,9 +4,12 @@ pub mod job_worker;
pub mod worker;
use core::future::Future;
+
+use std::collections::HashMap;
use std::pin::Pin;
use std::sync::Arc;
+use serde::{Deserialize, Serialize};
use tokio::sync::{mpsc, watch, Mutex};
use crate::error::Error;
@@ -20,6 +23,14 @@ pub(crate) type Job = Pin<Box<dyn Future<Output = JobOutput> + Send>>;
pub struct BackgroundRunner {
send_job: mpsc::UnboundedSender<(Job, bool)>,
send_worker: mpsc::UnboundedSender<Box<dyn Worker>>,
+ worker_info: Arc<std::sync::Mutex<HashMap<usize, WorkerInfo>>>,
+}
+
+#[derive(Clone, Serialize, Deserialize, Debug)]
+pub struct WorkerInfo {
+ pub name: String,
+ pub info: Option<String>,
+ pub status: WorkerStatus,
}
impl BackgroundRunner {
@@ -30,8 +41,13 @@ impl BackgroundRunner {
) -> (Arc<Self>, tokio::task::JoinHandle<()>) {
let (send_worker, worker_out) = mpsc::unbounded_channel::<Box<dyn Worker>>();
- let await_all_done =
- tokio::spawn(async move { WorkerProcessor::new(worker_out, stop_signal).run().await });
+ let worker_info = Arc::new(std::sync::Mutex::new(HashMap::new()));
+ let mut worker_processor =
+ WorkerProcessor::new(worker_out, stop_signal, worker_info.clone());
+
+ let await_all_done = tokio::spawn(async move {
+ worker_processor.run().await;
+ });
let (send_job, queue_out) = mpsc::unbounded_channel();
let queue_out = Arc::new(Mutex::new(queue_out));
@@ -52,10 +68,15 @@ impl BackgroundRunner {
let bgrunner = Arc::new(Self {
send_job,
send_worker,
+ worker_info,
});
(bgrunner, await_all_done)
}
+ pub fn get_worker_info(&self) -> HashMap<usize, WorkerInfo> {
+ self.worker_info.lock().unwrap().clone()
+ }
+
/// Spawn a task to be run in background
pub fn spawn<T>(&self, job: T)
where