use async_trait::async_trait;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct QueuedExecutorJob {
pub version: u16,
pub tenant: String,
pub owner: String,
pub task_id: String,
pub context_id: String,
pub message: turul_a2a_proto::Message,
pub claims: Option<serde_json::Value>,
#[serde(default)]
pub accepted_output_modes: Vec<String>,
#[serde(default)]
pub request_metadata: Option<serde_json::Value>,
#[serde(default)]
pub activated_extensions: Vec<String>,
pub enqueued_at_micros: i64,
}
impl QueuedExecutorJob {
pub const VERSION: u16 = 1;
pub fn new(
tenant: impl Into<String>,
owner: impl Into<String>,
task_id: impl Into<String>,
context_id: impl Into<String>,
message: turul_a2a_proto::Message,
enqueued_at_micros: i64,
) -> Self {
Self {
version: Self::VERSION,
tenant: tenant.into(),
owner: owner.into(),
task_id: task_id.into(),
context_id: context_id.into(),
message,
claims: None,
accepted_output_modes: Vec::new(),
request_metadata: None,
activated_extensions: Vec::new(),
enqueued_at_micros,
}
}
}
#[derive(Debug, thiserror::Error)]
pub enum QueueError {
#[error("failed to encode queue payload: {0}")]
Encode(#[from] serde_json::Error),
#[error("queue payload too large: {actual} bytes exceeds limit of {max} bytes")]
PayloadTooLarge { actual: usize, max: usize },
#[error("queue transport error: {0}")]
Transport(String),
}
#[async_trait]
pub trait DurableExecutorQueue: Send + Sync {
fn max_payload_bytes(&self) -> usize;
fn check_payload_size(&self, job: &QueuedExecutorJob) -> Result<usize, QueueError> {
let encoded = serde_json::to_vec(job)?;
let max = self.max_payload_bytes();
if encoded.len() > max {
Err(QueueError::PayloadTooLarge {
actual: encoded.len(),
max,
})
} else {
Ok(encoded.len())
}
}
async fn enqueue(&self, job: QueuedExecutorJob) -> Result<(), QueueError>;
fn kind(&self) -> &'static str;
}