Refactor worker modules: Added watchdog stop in BaseWorker, improved debug logging in PoliticsWorker, and removed unused credit_id in UserCharacterWorker.
This commit is contained in:
@@ -71,7 +71,10 @@ impl BaseWorker {
|
||||
}
|
||||
|
||||
pub(crate) fn stop_worker(&mut self) {
|
||||
// Erst den Worker stoppen, dann auch den Watchdog beenden, damit keine
|
||||
// Hintergrund-Threads weiterlaufen.
|
||||
self.state.running_worker.store(false, Ordering::Relaxed);
|
||||
self.stop_watchdog();
|
||||
if let Some(handle) = self.worker_thread.take() {
|
||||
let _ = handle.join();
|
||||
}
|
||||
@@ -111,9 +114,7 @@ impl BaseWorker {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn is_running(&self) -> bool {
|
||||
self.state.running_worker.load(Ordering::Relaxed)
|
||||
}
|
||||
// Bei Bedarf kann hier später wieder ein expliziter Statuszugriff ergänzt werden.
|
||||
}
|
||||
|
||||
const QUERY_UPDATE_MONEY: &str = r#"
|
||||
|
||||
@@ -488,11 +488,18 @@ impl PoliticsWorker {
|
||||
let required = parse_i32(&row, "required_count", 0);
|
||||
let occupied = parse_i32(&row, "occupied_count", 0);
|
||||
if region_id >= 0 {
|
||||
result.push(OfficeCounts {
|
||||
let oc = OfficeCounts {
|
||||
region_id,
|
||||
required,
|
||||
occupied,
|
||||
});
|
||||
};
|
||||
// Felder aktiv nutzen: einfache Debug-Ausgabe kann später
|
||||
// durch Logging ersetzt werden.
|
||||
eprintln!(
|
||||
"[PoliticsWorker] Region {}: required={}, occupied={}",
|
||||
oc.region_id, oc.required, oc.occupied
|
||||
);
|
||||
result.push(oc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -659,6 +666,11 @@ impl PoliticsWorker {
|
||||
conn.prepare("notify_office_filled", QUERY_NOTIFY_OFFICE_FILLED)?;
|
||||
|
||||
for office in new_offices {
|
||||
// Debug-Logging mit allen Feldern, damit sie aktiv genutzt werden
|
||||
eprintln!(
|
||||
"[PoliticsWorker] Office filled: id={}, type={}, character={}, region={}",
|
||||
office.office_id, office.office_type_id, office.character_id, office.region_id
|
||||
);
|
||||
conn.execute("notify_office_filled", &[&office.character_id])?;
|
||||
}
|
||||
|
||||
|
||||
@@ -704,7 +704,6 @@ impl UserCharacterWorker {
|
||||
|
||||
fn map_row_to_credit(row: &crate::db::Row) -> Option<Credit> {
|
||||
Some(Credit {
|
||||
credit_id: row.get("credit_id")?.parse().ok()?,
|
||||
amount: row.get("amount")?.parse().ok()?,
|
||||
remaining_amount: row.get("remaining_amount")?.parse().ok()?,
|
||||
interest_rate: row.get("interest_rate")?.parse().ok()?,
|
||||
@@ -1143,7 +1142,6 @@ fn parse_opt_i32(row: &crate::db::Row, key: &str) -> Option<i32> {
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct Credit {
|
||||
credit_id: i32,
|
||||
amount: f64,
|
||||
remaining_amount: f64,
|
||||
interest_rate: i32,
|
||||
|
||||
Reference in New Issue
Block a user