Full management surfaces for the platform-admin tenant, mirroring the existing Tenants pattern (DataTable + row actions + create/edit dialogs + ConfirmDialog for destructive ops, all data-action tagged for the command bus, useRegisterAdminContext publishing for the assistant). - Storage (/storage): backends + credentials. Write-only secret fields, Validate/Activate/Deactivate/Set-default/Mark-degraded/Maintenance. - Users (/users): tabs for Users, Invitations, Roles. Per-user View drawer with profile, role add/remove, API keys (one-time reveal on create), usage + quota. - Secrets (/secrets): /api/v1/admin/secrets — create/rotate/rollback, versions dialog, enable/disable, generate-value helper. - Webhooks (/webhooks): CRUD, pause/resume, regenerate-secret with one-time reveal, send test event, deliveries dialog. - Scheduled tasks (/scheduled-tasks): cron CRUD, run-now trigger, enable/disable, expandable run history. - Audit log (/activity): replaces the empty stub. Filter by severity, resource type, date range; click for full JSON detail. All endpoints are hand-rolled HTTP because most aren't covered by the generated OpenAPI typed paths yet — switch to arcadia.typed.* when the backend wires them into OpenApiSpex. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
131 lines
3.3 KiB
TypeScript
131 lines
3.3 KiB
TypeScript
// Scheduled tasks (cron) helpers.
|
|
// Backend: /api/v1/admin/scheduled-tasks (CRUD + runs/enable/disable/trigger).
|
|
|
|
import type { ArcadiaClient } from "@crema/arcadia-client"
|
|
|
|
export type ScheduledTaskAction = "webhook" | "event"
|
|
|
|
export interface ScheduledTask {
|
|
id: string
|
|
tenant_id: string | null
|
|
name: string
|
|
description: string | null
|
|
cron_expression: string
|
|
timezone: string
|
|
action_type: ScheduledTaskAction
|
|
/** Backend-encrypted; rendered as null on read but accepted on writes. */
|
|
action_config?: Record<string, unknown> | null
|
|
tags: string[]
|
|
enabled: boolean
|
|
last_run_at: string | null
|
|
next_run_at: string | null
|
|
max_retries: number
|
|
timeout_seconds: number
|
|
inserted_at: string
|
|
updated_at: string
|
|
}
|
|
|
|
export interface ScheduledTaskInput {
|
|
name: string
|
|
description?: string | null
|
|
cron_expression: string
|
|
timezone?: string
|
|
action_type: ScheduledTaskAction
|
|
action_config: Record<string, unknown>
|
|
tags?: string[]
|
|
enabled?: boolean
|
|
max_retries?: number
|
|
timeout_seconds?: number
|
|
}
|
|
|
|
export interface TaskRun {
|
|
id: string
|
|
task_id: string
|
|
status: "pending" | "running" | "succeeded" | "failed" | string
|
|
attempt: number
|
|
started_at: string | null
|
|
finished_at: string | null
|
|
response_status: number | null
|
|
response_body: string | null
|
|
error: string | null
|
|
inserted_at: string
|
|
}
|
|
|
|
const BASE = "/api/v1/admin/scheduled-tasks"
|
|
|
|
export async function listScheduledTasks(arcadia: ArcadiaClient): Promise<ScheduledTask[]> {
|
|
const res = await arcadia.GET<{ data: ScheduledTask[] }>(BASE)
|
|
return res.data
|
|
}
|
|
|
|
export async function getScheduledTask(
|
|
arcadia: ArcadiaClient,
|
|
id: string,
|
|
): Promise<ScheduledTask> {
|
|
const res = await arcadia.GET<{ data: ScheduledTask }>(`${BASE}/${id}`)
|
|
return res.data
|
|
}
|
|
|
|
export async function createScheduledTask(
|
|
arcadia: ArcadiaClient,
|
|
input: ScheduledTaskInput,
|
|
): Promise<ScheduledTask> {
|
|
const res = await arcadia.POST<{ data: ScheduledTask }>(BASE, {
|
|
body: { scheduled_task: input },
|
|
})
|
|
return res.data
|
|
}
|
|
|
|
export async function updateScheduledTask(
|
|
arcadia: ArcadiaClient,
|
|
id: string,
|
|
input: Partial<ScheduledTaskInput>,
|
|
): Promise<ScheduledTask> {
|
|
const res = await arcadia.PATCH<{ data: ScheduledTask }>(`${BASE}/${id}`, {
|
|
body: { scheduled_task: input },
|
|
})
|
|
return res.data
|
|
}
|
|
|
|
export async function deleteScheduledTask(
|
|
arcadia: ArcadiaClient,
|
|
id: string,
|
|
): Promise<void> {
|
|
await arcadia.DELETE(`${BASE}/${id}`)
|
|
}
|
|
|
|
export async function enableScheduledTask(
|
|
arcadia: ArcadiaClient,
|
|
id: string,
|
|
): Promise<ScheduledTask> {
|
|
const res = await arcadia.POST<{ data: ScheduledTask }>(`${BASE}/${id}/enable`)
|
|
return res.data
|
|
}
|
|
|
|
export async function disableScheduledTask(
|
|
arcadia: ArcadiaClient,
|
|
id: string,
|
|
): Promise<ScheduledTask> {
|
|
const res = await arcadia.POST<{ data: ScheduledTask }>(`${BASE}/${id}/disable`)
|
|
return res.data
|
|
}
|
|
|
|
export async function triggerScheduledTask(
|
|
arcadia: ArcadiaClient,
|
|
id: string,
|
|
): Promise<TaskRun> {
|
|
const res = await arcadia.POST<{ data: TaskRun }>(`${BASE}/${id}/trigger`)
|
|
return res.data
|
|
}
|
|
|
|
export async function listTaskRuns(
|
|
arcadia: ArcadiaClient,
|
|
id: string,
|
|
params?: { limit?: number; offset?: number },
|
|
): Promise<TaskRun[]> {
|
|
const res = await arcadia.GET<{ data: TaskRun[] }>(`${BASE}/${id}/runs`, {
|
|
params: params as Record<string, number | undefined>,
|
|
})
|
|
return res.data
|
|
}
|