use super::super::types::*;
use super::core::BatchProcessor;
use crate::utils::error::gateway_error::Result;
use chrono::Utc;
impl BatchProcessor {
pub(super) async fn update_batch_status(
&self,
batch_id: &str,
status: BatchStatus,
) -> Result<()> {
{
let mut active = self.active_batches.write().await;
if let Some(batch) = active.get_mut(batch_id) {
batch.status = status.clone();
}
}
self.database
.update_batch_status(batch_id, &format!("{:?}", status))
.await
}
pub(super) async fn update_batch_progress(
&self,
batch_id: &str,
completed: u32,
failed: u32,
) -> Result<()> {
{
let mut active = self.active_batches.write().await;
if let Some(batch) = active.get_mut(batch_id) {
batch.request_counts.completed = completed as i32;
batch.request_counts.failed = failed as i32;
}
}
self.database
.update_batch_progress(batch_id, completed as i32, failed as i32)
.await
}
pub(super) async fn mark_batch_completed(&self, batch_id: &str) -> Result<()> {
let now = Utc::now();
{
let mut active = self.active_batches.write().await;
if let Some(batch) = active.get_mut(batch_id) {
batch.completed_at = Some(now);
}
}
self.database.mark_batch_completed(batch_id).await
}
pub(super) async fn is_batch_cancelled(&self, batch_id: &str) -> Result<bool> {
let active = self.active_batches.read().await;
if let Some(batch) = active.get(batch_id) {
Ok(matches!(
batch.status,
BatchStatus::Cancelling | BatchStatus::Cancelled
))
} else {
Ok(false)
}
}
}