Initial commit: Rust YpDaemon

This commit is contained in:
Torsten Schulz (local)
2025-11-21 23:05:34 +01:00
commit d0ec363f09
21 changed files with 8067 additions and 0 deletions

49
src/worker/simple.rs Normal file
View 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();
}
}
};
}