排程管理及排程记录查看功能
This commit is contained in:
1 parent
3b31867319
commit
08776feef2
28 files changed
+3040
-8
No files matched your search
@@ -0,0 +1,97 @@
|
||||
import { getAuthHeaders } from '../utils/auth';
|
||||
|
||||
export interface ScheduleTask {
|
||||
id: number;
|
||||
schedule_no: string;
|
||||
name: string;
|
||||
schedule_type: string;
|
||||
owner_user_id: number;
|
||||
owner_username?: string | null;
|
||||
cron_expr: string;
|
||||
wait_seconds: number;
|
||||
dify_agent_id?: number | null;
|
||||
platform_api_path?: string | null;
|
||||
notify_user_ids_json: number[];
|
||||
notify_enabled: boolean;
|
||||
enabled: boolean;
|
||||
next_run_at?: string | null;
|
||||
last_run_at?: string | null;
|
||||
last_status?: string | null;
|
||||
created_at?: string | null;
|
||||
updated_at?: string | null;
|
||||
}
|
||||
|
||||
export interface ScheduleRun {
|
||||
id: number;
|
||||
run_no: string;
|
||||
schedule_task_id: number;
|
||||
schedule_name?: string | null;
|
||||
trigger_type: string;
|
||||
started_at?: string | null;
|
||||
finished_at?: string | null;
|
||||
duration_ms: number;
|
||||
status: string;
|
||||
total_count: number;
|
||||
success_count: number;
|
||||
failed_count: number;
|
||||
skipped_count: number;
|
||||
api_request_json?: Record<string, any> | null;
|
||||
api_response_json?: Record<string, any> | null;
|
||||
response_summary_json?: Record<string, any> | null;
|
||||
error_message?: string | null;
|
||||
excel_file_name?: string | null;
|
||||
excel_file_size?: number | null;
|
||||
mail_sent: boolean;
|
||||
mail_sent_at?: string | null;
|
||||
mail_error?: string | null;
|
||||
created_at?: string | null;
|
||||
}
|
||||
|
||||
async function getJson<T>(url: string): Promise<T> {
|
||||
const res = await fetch(url, { headers: getAuthHeaders() });
|
||||
if (!res.ok) throw new Error((await res.json().catch(() => ({})))?.error || 'Request failed');
|
||||
return (await res.json()) as T;
|
||||
}
|
||||
|
||||
export const listAdminSchedules = () => getJson<ScheduleTask[]>('/api/admin/schedules');
|
||||
export const createAdminSchedule = (payload: Partial<ScheduleTask>) =>
|
||||
fetch('/api/admin/schedules', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', ...getAuthHeaders() },
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
export const updateAdminSchedule = (id: number, payload: Partial<ScheduleTask>) =>
|
||||
fetch(`/api/admin/schedules/${id}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json', ...getAuthHeaders() },
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
export const deleteAdminSchedule = (id: number) =>
|
||||
fetch(`/api/admin/schedules/${id}`, {
|
||||
method: 'DELETE',
|
||||
headers: getAuthHeaders(),
|
||||
});
|
||||
export const runAdminSchedule = (id: number) =>
|
||||
fetch(`/api/admin/schedules/${id}/run`, { method: 'POST', headers: getAuthHeaders() });
|
||||
export const toggleAdminSchedule = (id: number, enabled: boolean) =>
|
||||
fetch(`/api/admin/schedules/${id}/${enabled ? 'enable' : 'disable'}`, { method: 'POST', headers: getAuthHeaders() });
|
||||
export const listAdminScheduleRuns = (taskId: number, params?: { status?: string; started_after?: string; started_before?: string }) => {
|
||||
const sp = new URLSearchParams();
|
||||
if (params?.status) sp.set('status', params.status);
|
||||
if (params?.started_after) sp.set('started_after', params.started_after);
|
||||
if (params?.started_before) sp.set('started_before', params.started_before);
|
||||
const qs = sp.toString();
|
||||
return getJson<ScheduleRun[]>(`/api/admin/schedules/${taskId}/runs${qs ? '?' + qs : ''}`);
|
||||
};
|
||||
export const adminRunExcelUrl = (runId: number) => `/api/admin/schedule-runs/${runId}/excel`;
|
||||
|
||||
export const listWorkspaceScheduleRuns = (params?: { status?: string; schedule_name?: string; started_after?: string; started_before?: string }) => {
|
||||
const sp = new URLSearchParams();
|
||||
if (params?.status) sp.set('status', params.status);
|
||||
if (params?.schedule_name) sp.set('schedule_name', params.schedule_name);
|
||||
if (params?.started_after) sp.set('started_after', params.started_after);
|
||||
if (params?.started_before) sp.set('started_before', params.started_before);
|
||||
const qs = sp.toString();
|
||||
return getJson<ScheduleRun[]>(`/api/workspace/schedule-runs${qs ? '?' + qs : ''}`);
|
||||
};
|
||||
export const workspaceRunExcelUrl = (runId: number) => `/api/workspace/schedule-runs/${runId}/excel`;
|
||||
Reference in new issue
Block a user