crawlrs 0.2.0

crawlrs - Enterprise-grade web scraping and crawling platform built with Rust
Documentation
// Copyright (c) 2025-2026 Kirky.X🌠
// SPDX-License-Identifier: Apache-2.0

use super::task_repository::RepositoryError;
use crate::domain::models::WebhookEvent;
use async_trait::async_trait;

/// Webhook仓库特质
///
/// 定义Webhook事件数据访问接口
#[async_trait]
pub trait WebhookEventRepository: Send + Sync {
    /// 创建Webhook事件
    async fn create(&self, event: &WebhookEvent) -> Result<WebhookEvent, RepositoryError>;
    /// 根据ID查找Webhook事件
    async fn find_by_id(
        &self,
        id: crate::domain::id::Id,
    ) -> Result<Option<WebhookEvent>, RepositoryError>;
    /// 查找待处理的Webhook事件
    async fn find_pending(&self, limit: u64) -> Result<Vec<WebhookEvent>, RepositoryError>;
    /// 原子认领待投递的Webhook事件
    ///
    /// 将候选事件(pending、到达重试时间的 failed、超时未终结的 processing)
    /// 以 `FOR UPDATE SKIP LOCKED` 方式原子置为 `processing` 并返回,
    /// 保证多实例/多进程下同一事件只被一个消费者投递。
    async fn claim_pending(&self, limit: u64) -> Result<Vec<WebhookEvent>, RepositoryError>;
    /// 根据团队ID分页查询Webhook事件
    async fn find_by_team_id_paginated(
        &self,
        team_id: crate::domain::id::Id,
        limit: u32,
        offset: u32,
    ) -> Result<Vec<WebhookEvent>, RepositoryError>;
    /// 统计团队Webhook事件数量
    async fn count_by_team_id(
        &self,
        team_id: crate::domain::id::Id,
    ) -> Result<u64, RepositoryError>;
    /// 更新Webhook事件
    async fn update(&self, event: &WebhookEvent) -> Result<WebhookEvent, RepositoryError>;
}