feat(core): implement event outbox persistence

Add domain_events migration and SeaORM entity. Modify EventBus::publish
to persist events before broadcasting (best-effort: DB failure logs
warning but still broadcasts in-memory). Update all 19 publish call
sites across 4 crates to pass db reference.

Add outbox relay background task that polls pending events every 5s
and re-broadcasts them, ensuring no events are lost on server restart.
This commit is contained in:
iven
2026-04-12 00:10:49 +08:00
parent 529d90ff46
commit 685df5e458
23 changed files with 235 additions and 31 deletions

View File

@@ -137,7 +137,7 @@ impl DictionaryService {
"dictionary.created",
tenant_id,
serde_json::json!({ "dictionary_id": id, "code": code }),
));
), db).await;
audit_service::record(
AuditLog::new(tenant_id, Some(operator_id), "dictionary.create", "dictionary")
@@ -248,7 +248,7 @@ impl DictionaryService {
"dictionary.deleted",
tenant_id,
serde_json::json!({ "dictionary_id": id }),
));
), db).await;
audit_service::record(
AuditLog::new(tenant_id, Some(operator_id), "dictionary.delete", "dictionary")

View File

@@ -156,7 +156,7 @@ impl MenuService {
"menu.created",
tenant_id,
serde_json::json!({ "menu_id": id, "title": req.title }),
));
), db).await;
audit_service::record(
AuditLog::new(tenant_id, Some(operator_id), "menu.create", "menu")
@@ -289,7 +289,7 @@ impl MenuService {
"menu.deleted",
tenant_id,
serde_json::json!({ "menu_id": id }),
));
), db).await;
audit_service::record(
AuditLog::new(tenant_id, Some(operator_id), "menu.delete", "menu")

View File

@@ -107,7 +107,7 @@ impl NumberingService {
"numbering_rule.created",
tenant_id,
serde_json::json!({ "rule_id": id, "code": req.code }),
));
), db).await;
audit_service::record(
AuditLog::new(tenant_id, Some(operator_id), "numbering_rule.create", "numbering_rule")
@@ -223,7 +223,7 @@ impl NumberingService {
"numbering_rule.deleted",
tenant_id,
serde_json::json!({ "rule_id": id }),
));
), db).await;
audit_service::record(
AuditLog::new(tenant_id, Some(operator_id), "numbering_rule.delete", "numbering_rule")

View File

@@ -117,7 +117,7 @@ impl SettingService {
"key": params.key,
"scope": params.scope,
}),
));
), db).await;
audit_service::record(
AuditLog::new(tenant_id, Some(operator_id), "setting.upsert", "setting")
@@ -158,7 +158,7 @@ impl SettingService {
"key": params.key,
"scope": params.scope,
}),
));
), db).await;
audit_service::record(
AuditLog::new(tenant_id, Some(operator_id), "setting.upsert", "setting")