Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

1.0 KB
Raw Blame
//! Per-inbox Google Calendar request gate for disconnecting an inbox's calendar.

use calendar_events::domain::ports::{CalendarProviderError, CalendarProviderErrorKind};
use calendar_events::outbound::google::GoogleRequestGate;
use uuid::Uuid;

use crate::util::redis::RedisClient;

/// Enforces the per-inbox Google Calendar API quota before each request.
#[derive(Clone)]
pub struct RedisCalendarRequestGate {
    redis: RedisClient,
}

impl RedisCalendarRequestGate {
    /// Construct the gate over the process-level Redis client.
    pub fn new(redis: RedisClient) -> Self {
        Self { redis }
    }
}

impl GoogleRequestGate for RedisCalendarRequestGate {
    async fn acquire(&self, email_link_id: Uuid) -> Result<(), CalendarProviderError> {
        if self.redis.is_calendar_rate_limited(email_link_id).await {
            return Err(CalendarProviderError::new(
                CalendarProviderErrorKind::Transient,
                "Google Calendar API rate limit reached for this inbox",
            ));
        }
        Ok(())
    }
}