Skip to main content

commit_bridge/repository/
trigger.rs

1//! Repository access for the `trigger_queue` table.
2
3use crate::model::TriggerQueueItem;
4use crate::repository::RepositoryError;
5use async_trait::async_trait;
6
7/// Parameters for updating a trigger's retry status.
8#[derive(Debug, Clone)]
9pub struct UpdateRetryStatus {
10    /// The unique identifier of the trigger.
11    pub id: i64,
12
13    /// The current retry count of the trigger.
14    pub retry_count: i64,
15
16    /// The maximum number of attempts allowed.
17    pub max_attempts: u32,
18
19    /// The base backoff duration in seconds.
20    pub backoff_base_secs: u64,
21}
22
23/// Interface for `trigger_queue` table operations.
24#[async_trait]
25pub trait TriggerRepository: Send + Sync {
26    /// Returns all the trigger queue items.
27    async fn get_all(&self) -> Result<Vec<TriggerQueueItem>, RepositoryError>;
28
29    /// Finds the oldest pending trigger queue item and marks it as processing in a transaction.
30    async fn find_oldest_pending_and_mark_processing(
31        &self,
32    ) -> Result<Option<TriggerQueueItem>, RepositoryError>;
33
34    /// Schedules a retry or marks the trigger as failed if max attempts is reached.
35    async fn update_retry_status(&self, params: UpdateRetryStatus) -> Result<(), RepositoryError>;
36
37    /// Recovers tasks that have been stuck in `PROCESSING` for too long.
38    async fn recover_stuck_tasks(&self, threshold_seconds: u64) -> Result<(), RepositoryError>;
39
40    /// Deletes the trigger queue item with the given `id`.
41    async fn delete_by_id(&self, id: i64) -> Result<(), RepositoryError>;
42
43    /// Queues trigger events for all subscriptions of a branch.
44    async fn queue_triggers_for_branch(
45        &self,
46        branch_id: i64,
47        new_hash: &crate::domain::CommitHash,
48        executor: &mut sqlx::SqliteConnection,
49    ) -> Result<(), RepositoryError>;
50}