Initial commit: Rust YpDaemon
This commit is contained in:
49
src/worker/simple.rs
Normal file
49
src/worker/simple.rs
Normal file
@@ -0,0 +1,49 @@
|
||||
use crate::message_broker::MessageBroker;
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::sync::Arc;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::db::ConnectionPool;
|
||||
use super::base::{BaseWorker, Worker, WorkerState};
|
||||
|
||||
macro_rules! define_simple_worker {
|
||||
($name:ident) => {
|
||||
pub struct $name {
|
||||
base: BaseWorker,
|
||||
}
|
||||
|
||||
impl $name {
|
||||
pub fn new(pool: ConnectionPool, broker: MessageBroker) -> Self {
|
||||
Self {
|
||||
base: BaseWorker::new(stringify!($name), pool, broker),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Worker for $name {
|
||||
fn start_worker_thread(&mut self) {
|
||||
self.base
|
||||
.start_worker_with_loop(|state: Arc<WorkerState>| {
|
||||
// Einfache Dummy-Schleife, bis echte Logik portiert ist
|
||||
while state.running_worker.load(Ordering::Relaxed) {
|
||||
if let Ok(mut step) = state.current_step.lock() {
|
||||
*step = format!("{}: idle", stringify!($name));
|
||||
}
|
||||
thread::sleep(Duration::from_secs(5));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn stop_worker_thread(&mut self) {
|
||||
self.base.stop_worker();
|
||||
}
|
||||
|
||||
fn enable_watchdog(&mut self) {
|
||||
self.base.start_watchdog();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user