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:
@@ -130,7 +130,7 @@ impl AuthService {
|
||||
"user.login",
|
||||
tenant_id,
|
||||
serde_json::json!({ "user_id": user_model.id, "username": user_model.username }),
|
||||
));
|
||||
), db).await;
|
||||
|
||||
Ok(LoginResp {
|
||||
access_token,
|
||||
|
||||
@@ -124,7 +124,7 @@ impl DeptService {
|
||||
"department.created",
|
||||
tenant_id,
|
||||
serde_json::json!({ "dept_id": id, "org_id": org_id, "name": req.name }),
|
||||
));
|
||||
), db).await;
|
||||
|
||||
audit_service::record(
|
||||
AuditLog::new(tenant_id, Some(operator_id), "department.create", "department")
|
||||
@@ -271,7 +271,7 @@ impl DeptService {
|
||||
"department.deleted",
|
||||
tenant_id,
|
||||
serde_json::json!({ "dept_id": id }),
|
||||
));
|
||||
), db).await;
|
||||
|
||||
audit_service::record(
|
||||
AuditLog::new(tenant_id, Some(operator_id), "department.delete", "department")
|
||||
|
||||
@@ -110,7 +110,7 @@ impl OrgService {
|
||||
"organization.created",
|
||||
tenant_id,
|
||||
serde_json::json!({ "org_id": id, "name": req.name }),
|
||||
));
|
||||
), db).await;
|
||||
|
||||
audit_service::record(
|
||||
AuditLog::new(tenant_id, Some(operator_id), "organization.create", "organization")
|
||||
@@ -250,7 +250,7 @@ impl OrgService {
|
||||
"organization.deleted",
|
||||
tenant_id,
|
||||
serde_json::json!({ "org_id": id }),
|
||||
));
|
||||
), db).await;
|
||||
|
||||
audit_service::record(
|
||||
AuditLog::new(tenant_id, Some(operator_id), "organization.delete", "organization")
|
||||
|
||||
@@ -109,7 +109,7 @@ impl PositionService {
|
||||
"position.created",
|
||||
tenant_id,
|
||||
serde_json::json!({ "position_id": id, "dept_id": dept_id, "name": req.name }),
|
||||
));
|
||||
), db).await;
|
||||
|
||||
audit_service::record(
|
||||
AuditLog::new(tenant_id, Some(operator_id), "position.create", "position")
|
||||
@@ -234,7 +234,7 @@ impl PositionService {
|
||||
"position.deleted",
|
||||
tenant_id,
|
||||
serde_json::json!({ "position_id": id }),
|
||||
));
|
||||
), db).await;
|
||||
|
||||
audit_service::record(
|
||||
AuditLog::new(tenant_id, Some(operator_id), "position.delete", "position")
|
||||
|
||||
@@ -131,7 +131,7 @@ impl RoleService {
|
||||
"role.created",
|
||||
tenant_id,
|
||||
serde_json::json!({ "role_id": id, "code": code }),
|
||||
));
|
||||
), db).await;
|
||||
|
||||
audit_service::record(
|
||||
AuditLog::new(tenant_id, Some(operator_id), "role.create", "role")
|
||||
@@ -242,7 +242,7 @@ impl RoleService {
|
||||
"role.deleted",
|
||||
tenant_id,
|
||||
serde_json::json!({ "role_id": id }),
|
||||
));
|
||||
), db).await;
|
||||
|
||||
audit_service::record(
|
||||
AuditLog::new(tenant_id, Some(operator_id), "role.delete", "role")
|
||||
|
||||
@@ -94,7 +94,7 @@ impl UserService {
|
||||
"user.created",
|
||||
tenant_id,
|
||||
serde_json::json!({ "user_id": user_id, "username": req.username }),
|
||||
));
|
||||
), db).await;
|
||||
|
||||
audit_service::record(
|
||||
AuditLog::new(tenant_id, Some(operator_id), "user.create", "user")
|
||||
@@ -265,7 +265,7 @@ impl UserService {
|
||||
"user.deleted",
|
||||
tenant_id,
|
||||
serde_json::json!({ "user_id": id }),
|
||||
));
|
||||
), db).await;
|
||||
|
||||
audit_service::record(
|
||||
AuditLog::new(tenant_id, Some(operator_id), "user.delete", "user")
|
||||
|
||||
Reference in New Issue
Block a user