MATIH Platform is in active MVP development. Documentation reflects current implementation status.
9. Query Engine & SQL
Query Scheduling

Query Scheduling

The QueryScheduleController enables automated, recurring query execution. Schedules support cron expressions, interval-based timing, and one-time execution with full lifecycle management.


Base Path

/v1/schedules

Create a Schedule

curl -X POST http://query-engine:8080/v1/schedules \
  -H "Content-Type: application/json" \
  -H "X-Tenant-ID: 550e8400-e29b-41d4-a716-446655440000" \
  -H "X-User-ID: 6ba7b810-9dad-11d1-80b4-00c04fd430c8" \
  -H "Authorization: Bearer $JWT_TOKEN" \
  -d '{
    "name": "Daily Revenue Report",
    "description": "Generates daily revenue summary by region",
    "queryText": "SELECT region, SUM(revenue) as total FROM orders WHERE order_date = current_date - interval '\''1'\'' day GROUP BY region",
    "scheduleType": "CRON",
    "cronExpression": "0 0 6 * * ?",
    "timezone": "America/New_York",
    "engineType": "TRINO",
    "maxRetries": 3,
    "retryDelaySeconds": 60,
    "timeoutSeconds": 3600,
    "priority": 3,
    "storeResults": true,
    "resultRetentionDays": 30,
    "notifyOnSuccess": false,
    "notifyOnFailure": true,
    "notificationEmails": "data-team@example.com"
  }'

Schedule Types

TypeConfigurationExample
ONCEstartTimeRun once at a specific time
INTERVALintervalSecondsRun every N seconds
CRONcronExpressionCron-based scheduling
DAILYstartTime + timezoneRun daily at a specific time
WEEKLYstartTime + timezoneRun weekly
MONTHLYstartTime + timezoneRun monthly

Lifecycle Management

# List schedules
curl http://query-engine:8080/v1/schedules \
  -H "X-Tenant-ID: ..." \
  -H "Authorization: Bearer $JWT_TOKEN"
 
# Pause a schedule
curl -X POST http://query-engine:8080/v1/schedules/{scheduleId}/pause \
  -H "X-Tenant-ID: ..." \
  -H "Authorization: Bearer $JWT_TOKEN"
 
# Resume a paused schedule
curl -X POST http://query-engine:8080/v1/schedules/{scheduleId}/resume \
  -H "X-Tenant-ID: ..." \
  -H "Authorization: Bearer $JWT_TOKEN"
 
# Trigger immediate execution
curl -X POST http://query-engine:8080/v1/schedules/{scheduleId}/trigger \
  -H "X-Tenant-ID: ..." \
  -H "Authorization: Bearer $JWT_TOKEN"
 
# Delete a schedule
curl -X DELETE http://query-engine:8080/v1/schedules/{scheduleId} \
  -H "X-Tenant-ID: ..." \
  -H "Authorization: Bearer $JWT_TOKEN"

Execution History

curl http://query-engine:8080/v1/schedules/{scheduleId}/executions \
  -H "X-Tenant-ID: ..." \
  -H "Authorization: Bearer $JWT_TOKEN"
{
  "scheduleId": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
  "scheduleName": "Daily Revenue Report",
  "executionCount": 45,
  "successCount": 43,
  "failureCount": 2,
  "consecutiveFailures": 0,
  "lastExecutedAt": "2026-02-12T06:00:00Z",
  "lastExecutionStatus": "SUCCESS",
  "lastExecutionId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "nextScheduledAt": "2026-02-13T06:00:00Z"
}

Auto-Disable

Schedules are automatically disabled after 5 consecutive failures to prevent runaway error accumulation:

public boolean shouldAutoDisable() {
    return consecutiveFailures >= 5;
}

Schedule Status Values

StatusDescription
ACTIVESchedule is running normally
PAUSEDTemporarily paused by user
DISABLEDDisabled manually or auto-disabled after failures
COMPLETEDOne-time schedule has executed
EXPIREDPast the configured endTime