diff --git a/crates/common/src/mq/error.rs b/crates/common/src/mq/error.rs
index 318ed1a..e13c3f2 100644
--- a/crates/common/src/mq/error.rs
+++ b/crates/common/src/mq/error.rs
@@ -102,7 +102,12 @@ impl MqError {
pub fn is_retriable(&self) -> bool {
matches!(
self,
- MqError::Connection(_) | MqError::Channel(_) | MqError::Timeout(_) | MqError::Pool(_)
+ MqError::Connection(_)
+ | MqError::Channel(_)
+ | MqError::Publish(_)
+ | MqError::Timeout(_)
+ | MqError::Pool(_)
+ | MqError::Lapin(_)
)
}
diff --git a/crates/common/src/repositories/action.rs b/crates/common/src/repositories/action.rs
index 76a3d38..c265e31 100644
--- a/crates/common/src/repositories/action.rs
+++ b/crates/common/src/repositories/action.rs
@@ -571,7 +571,7 @@ impl Repository for PolicyRepository {
type Entity = Policy;
fn table_name() -> &'static str {
- "policies"
+ "policy"
}
}
@@ -612,7 +612,7 @@ impl FindById for PolicyRepository {
r#"
SELECT id, ref, pack, pack_ref, action, action_ref, parameters, method,
threshold, name, description, tags, created, updated
- FROM policies
+ FROM policy
WHERE id = $1
"#,
)
@@ -634,7 +634,7 @@ impl FindByRef for PolicyRepository {
r#"
SELECT id, ref, pack, pack_ref, action, action_ref, parameters, method,
threshold, name, description, tags, created, updated
- FROM policies
+ FROM policy
WHERE ref = $1
"#,
)
@@ -656,7 +656,7 @@ impl List for PolicyRepository {
r#"
SELECT id, ref, pack, pack_ref, action, action_ref, parameters, method,
threshold, name, description, tags, created, updated
- FROM policies
+ FROM policy
ORDER BY ref ASC
"#,
)
@@ -678,7 +678,7 @@ impl Create for PolicyRepository {
// Try to insert - database will enforce uniqueness constraint
let policy = sqlx::query_as::<_, Policy>(
r#"
- INSERT INTO policies (ref, pack, pack_ref, action, action_ref, parameters,
+ INSERT INTO policy (ref, pack, pack_ref, action, action_ref, parameters,
method, threshold, name, description, tags)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)
RETURNING id, ref, pack, pack_ref, action, action_ref, parameters, method,
@@ -720,7 +720,7 @@ impl Update for PolicyRepository {
where
E: Executor<'e, Database = Postgres> + 'e,
{
- let mut query = QueryBuilder::new("UPDATE policies SET ");
+ let mut query = QueryBuilder::new("UPDATE policy SET ");
let mut has_updates = false;
if let Some(parameters) = &input.parameters {
@@ -798,7 +798,7 @@ impl Delete for PolicyRepository {
where
E: Executor<'e, Database = Postgres> + 'e,
{
- let result = sqlx::query("DELETE FROM policies WHERE id = $1")
+ let result = sqlx::query("DELETE FROM policy WHERE id = $1")
.bind(id)
.execute(executor)
.await?;
@@ -817,7 +817,7 @@ impl PolicyRepository {
r#"
SELECT id, ref, pack, pack_ref, action, action_ref, parameters, method,
threshold, name, description, tags, created, updated
- FROM policies
+ FROM policy
WHERE action = $1
ORDER BY ref ASC
"#,
@@ -838,7 +838,7 @@ impl PolicyRepository {
r#"
SELECT id, ref, pack, pack_ref, action, action_ref, parameters, method,
threshold, name, description, tags, created, updated
- FROM policies
+ FROM policy
WHERE $1 = ANY(tags)
ORDER BY ref ASC
"#,
@@ -849,4 +849,69 @@ impl PolicyRepository {
Ok(policies)
}
+
+ /// Find the most recent action-specific policy.
+ pub async fn find_latest_by_action<'e, E>(executor: E, action_id: Id) -> Result