use crate::activity::activity::Activity;
use crate::runner::error::WorkerError;
use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use std::time::Duration;
#[async_trait]
pub(crate) trait ActivityQueueTrait: Send + Sync {
async fn enqueue(&self, activity: Activity) -> Result<(), WorkerError>;
async fn dequeue(
&self,
timeout: Duration,
worker_id: &str,
) -> Result<Option<Activity>, WorkerError>;
async fn mark_completed(&self, activity: &Activity, worker_id: &str)
-> Result<(), WorkerError>;
async fn mark_failed(
&self,
activity: Activity,
error_message: String,
retryable: bool,
worker_id: &str,
) -> Result<bool, WorkerError>;
async fn schedule_activity(&self, activity: Activity) -> Result<(), WorkerError>;
async fn process_scheduled_activities(&self) -> Result<Vec<Activity>, WorkerError>;
async fn requeue_expired(&self, max_to_process: usize) -> Result<u64, WorkerError>;
async fn evaluate_idempotency_rule(
&self,
activity: &Activity,
) -> Result<Option<uuid::Uuid>, WorkerError>;
#[allow(dead_code)]
async fn extend_lease(
&self,
activity_id: uuid::Uuid,
extend_by: std::time::Duration,
) -> Result<bool, WorkerError>;
async fn store_result(
&self,
activity_id: uuid::Uuid,
result: ActivityResult,
) -> Result<(), WorkerError>;
async fn get_result(
&self,
activity_id: uuid::Uuid,
) -> Result<Option<ActivityResult>, WorkerError>;
fn schedules_natively(&self) -> bool {
false
}
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub(crate) enum ResultState {
Ok,
Err,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub(crate) struct ActivityResult {
pub data: Option<serde_json::Value>,
pub state: ResultState,
}