# Scheduler Specifications

## Overview
Schedulers are responsible for managing periodic tasks that ensure data synchronization and system operations run smoothly. They handle tasks such as syncing data from connectors (e.g., GDrive, Gmail, GChat) and maintaining system health.

## Responsibilities
- GDrive Sync: Periodic sync of folders, files, and metadata.
- Gmail Sync: Periodic sync of emails, threads, and attachments.
- GChat Sync: Periodic sync of chat spaces, members, messages, and threads.

## Key Tasks
- GDrive Sync: Periodic sync of folders, files, and metadata.
- Gmail Sync: Periodic sync of emails, threads, and attachments.
- GChat Sync: Periodic sync of chat spaces, members, messages, and threads.

## Configuration
- Define sync intervals and priorities for each connector.
- Configure retry policies and error handling mechanisms.

## Observability
- Logs for task execution, failures, and retries.
- Metrics for task duration, success rates, and resource usage.

## Open Questions / TODO
- Define scaling strategies for high-frequency tasks.
- Explore dynamic scheduling based on system load.

## Technical Specifications

### Logging
- Schedulers log every sync operation into the database, including timestamps and details of what data was synced.
- This ensures that subsequent syncs can process only the delta of changes.

### Admin Control
- Administrators can enable or disable syncs for each connector via the admin settings.
- This provides flexibility to manage system load and prioritize specific connectors.

## Implementation Details

### Logging Sync Operations
- Each sync operation writes an entry to the `sync_logs` table in the database.
- Fields include:
  - `connector_name`: Name of the connector (e.g., GDrive, Gmail).
  - `sync_start_time` and `sync_end_time`.
  - `data_synced`: Summary of the data synced (e.g., number of files, emails).

### Delta Syncs
- Sync operations fetch only the changes since the last recorded sync time.
- This is achieved by querying the `sync_logs` table for the last successful sync timestamp.

### Admin Control Implementation
- Admin settings include toggles for each connector.
- These toggles update a `connector_status` table in the database.
- The scheduler checks the status of each connector before initiating a sync.

## User Roles and Permissions

### Administrators
- Enable or disable syncs for connectors.
- View sync logs and monitor sync performance.

### Regular Users
- No direct access to scheduler controls.
- Benefit from up-to-date data synced by the schedulers.