correctly processing enforcements
This commit is contained in:
@@ -11,15 +11,15 @@
|
||||
|
||||
use anyhow::{bail, Result};
|
||||
use attune_common::{
|
||||
models::{Enforcement, Event, Rule},
|
||||
models::{Enforcement, EnforcementStatus, Event, Rule},
|
||||
mq::{
|
||||
Consumer, EnforcementCreatedPayload, ExecutionRequestedPayload, MessageEnvelope, Publisher,
|
||||
},
|
||||
repositories::{
|
||||
event::{EnforcementRepository, EventRepository},
|
||||
event::{EnforcementRepository, EventRepository, UpdateEnforcementInput},
|
||||
execution::{CreateExecutionInput, ExecutionRepository},
|
||||
rule::RuleRepository,
|
||||
Create, FindById,
|
||||
Create, FindById, Update,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -144,11 +144,40 @@ impl EnforcementProcessor {
|
||||
&rule,
|
||||
)
|
||||
.await?;
|
||||
|
||||
// Update enforcement status to Processed after successful execution creation
|
||||
EnforcementRepository::update(
|
||||
pool,
|
||||
enforcement_id,
|
||||
UpdateEnforcementInput {
|
||||
status: Some(EnforcementStatus::Processed),
|
||||
payload: None,
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
|
||||
debug!("Updated enforcement {} status to Processed", enforcement_id);
|
||||
} else {
|
||||
info!(
|
||||
"Skipping execution creation for enforcement: {}",
|
||||
enforcement_id
|
||||
);
|
||||
|
||||
// Update enforcement status to Disabled since it was not actionable
|
||||
EnforcementRepository::update(
|
||||
pool,
|
||||
enforcement_id,
|
||||
UpdateEnforcementInput {
|
||||
status: Some(EnforcementStatus::Disabled),
|
||||
payload: None,
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
|
||||
debug!(
|
||||
"Updated enforcement {} status to Disabled (skipped)",
|
||||
enforcement_id
|
||||
);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -215,7 +244,8 @@ impl EnforcementProcessor {
|
||||
);
|
||||
bail!(
|
||||
"Rule {} references a deleted action (action_ref: {})",
|
||||
rule.id, rule.action_ref
|
||||
rule.id,
|
||||
rule.action_ref
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -15,6 +15,7 @@ const NOTIFICATION_CHANNELS: &[&str] = &[
|
||||
"inquiry_created",
|
||||
"inquiry_responded",
|
||||
"enforcement_created",
|
||||
"enforcement_status_changed",
|
||||
"event_created",
|
||||
"workflow_execution_status_changed",
|
||||
];
|
||||
@@ -167,6 +168,8 @@ mod tests {
|
||||
fn test_notification_channels_defined() {
|
||||
assert!(!NOTIFICATION_CHANNELS.is_empty());
|
||||
assert!(NOTIFICATION_CHANNELS.contains(&"execution_status_changed"));
|
||||
assert!(NOTIFICATION_CHANNELS.contains(&"enforcement_created"));
|
||||
assert!(NOTIFICATION_CHANNELS.contains(&"enforcement_status_changed"));
|
||||
assert!(NOTIFICATION_CHANNELS.contains(&"inquiry_created"));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user