QuperSyncAPI EndpointsFastAPI

QuperSync API Endpoints

QuperSync exposes a REST API for managing sync jobs, triggering on-demand syncs, and inspecting sync history. The API is implemented with FastAPI and runs on the same process as the scheduler.

Sync Management

GET
/api/v1/sync/status

Get the current status of all registered sync jobs including last run time, next scheduled run, and row counts

POST
/api/v1/sync/trigger

Trigger an immediate on-demand sync for a specific job or all jobs

GET
/api/v1/sync/jobs

List all registered sync jobs with their configurations and schedule intervals

POST
/api/v1/sync/jobs/{job_id}/pause

Pause a specific sync job (APScheduler pause)

POST
/api/v1/sync/jobs/{job_id}/resume

Resume a paused sync job

Sync History

GET
/api/v1/sync/history

List sync log entries with optional filtering by job, date range, and status

GET
/api/v1/sync/history/{log_id}

Get detailed information about a specific sync run including error details

DELETE
/api/v1/sync/history

Purge sync history older than a specified number of days

Health & Monitoring

GET
/health

Service health check — verifies both Redshift and PostgreSQL connectivity

GET
/metrics

Prometheus-format metrics for sync job duration, row counts, and error rates

Trigger On-Demand Sync

POST /api/v1/sync/trigger
// Request — trigger all jobs
{}

// Request — trigger specific job
{
  "job_id": "table_stats_sync"
}

// Response
{
  "success": true,
  "triggered_jobs": ["table_stats_sync"],
  "message": "Sync triggered successfully"
}

Sync Status Response

GET /api/v1/sync/status
{
  "status": "running",
  "scheduler_timezone": "US/Pacific",
  "jobs": [
    {
      "job_id": "table_stats_sync",
      "name": "Table Statistics Sync",
      "status": "active",
      "last_run": "2024-01-15T10:00:04.231Z",
      "next_run": "2024-01-15T10:05:00.000Z",
      "interval_seconds": 300,
      "last_result": {
        "rows_extracted": 1247,
        "rows_upserted": 1247,
        "duration_ms": 4231,
        "status": "success"
      }
    },
    {
      "job_id": "query_history_sync",
      "name": "Query History Sync (7d)",
      "status": "active",
      "last_run": "2024-01-15T10:00:12.891Z",
      "next_run": "2024-01-15T10:05:00.000Z",
      "interval_seconds": 300,
      "last_result": {
        "rows_extracted": 8432,
        "rows_upserted": 8432,
        "duration_ms": 12891,
        "status": "success"
      }
    }
  ]
}

Server-Sent Events for Real-Time Updates

QuperSync uses sse-starlette to stream sync progress events in real-time:

GET /api/v1/sync/stream
from sse_starlette.sse import EventSourceResponse

@router.get("/sync/stream")
async def sync_event_stream(request: Request):
    async def event_generator():
        while True:
            if await request.is_disconnected():
                break
            # Emit sync status update every 5 seconds
            status = await get_sync_status()
            yield {
                "event": "sync_update",
                "data": json.dumps(status)
            }
            await asyncio.sleep(5)

    return EventSourceResponse(event_generator())

Web UI Integration

The web dashboard uses Server-Sent Events to display real-time sync status indicators without polling. The connection is established when the admin views the QuperSync status page.