mirror of
https://github.com/khoaliber/dockhand.git
synced 2026-03-07 13:22:54 +00:00
Initial commit
This commit is contained in:
62
routes/api/schedules/executions/+server.ts
Normal file
62
routes/api/schedules/executions/+server.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* Schedule Executions API - List execution history
|
||||
*
|
||||
* GET /api/schedules/executions - Returns paginated execution history
|
||||
*
|
||||
* Query params:
|
||||
* - scheduleType: 'container_update' | 'git_stack_sync'
|
||||
* - scheduleId: number
|
||||
* - environmentId: number
|
||||
* - status: 'queued' | 'running' | 'success' | 'failed' | 'skipped'
|
||||
* - triggeredBy: 'cron' | 'webhook' | 'manual'
|
||||
* - fromDate: ISO date string
|
||||
* - toDate: ISO date string
|
||||
* - limit: number (default 50)
|
||||
* - offset: number (default 0)
|
||||
*/
|
||||
|
||||
import { json } from '@sveltejs/kit';
|
||||
import type { RequestHandler } from './$types';
|
||||
import {
|
||||
getScheduleExecutions,
|
||||
type ScheduleType,
|
||||
type ScheduleTrigger,
|
||||
type ScheduleStatus
|
||||
} from '$lib/server/db';
|
||||
|
||||
export const GET: RequestHandler = async ({ url }) => {
|
||||
try {
|
||||
const scheduleType = url.searchParams.get('scheduleType') as ScheduleType | null;
|
||||
const scheduleIdParam = url.searchParams.get('scheduleId');
|
||||
const environmentIdParam = url.searchParams.get('environmentId');
|
||||
const status = url.searchParams.get('status') as ScheduleStatus | null;
|
||||
const statusesParam = url.searchParams.get('statuses');
|
||||
const triggeredBy = url.searchParams.get('triggeredBy') as ScheduleTrigger | null;
|
||||
const fromDate = url.searchParams.get('fromDate');
|
||||
const toDate = url.searchParams.get('toDate');
|
||||
const limitParam = url.searchParams.get('limit');
|
||||
const offsetParam = url.searchParams.get('offset');
|
||||
|
||||
const filters: any = {};
|
||||
|
||||
if (scheduleType) filters.scheduleType = scheduleType;
|
||||
if (scheduleIdParam) filters.scheduleId = parseInt(scheduleIdParam, 10);
|
||||
if (environmentIdParam) {
|
||||
filters.environmentId = environmentIdParam === 'null' ? null : parseInt(environmentIdParam, 10);
|
||||
}
|
||||
if (status) filters.status = status;
|
||||
if (statusesParam) filters.statuses = statusesParam.split(',') as ScheduleStatus[];
|
||||
if (triggeredBy) filters.triggeredBy = triggeredBy;
|
||||
if (fromDate) filters.fromDate = fromDate;
|
||||
if (toDate) filters.toDate = toDate;
|
||||
if (limitParam) filters.limit = parseInt(limitParam, 10);
|
||||
if (offsetParam) filters.offset = parseInt(offsetParam, 10);
|
||||
|
||||
const result = await getScheduleExecutions(filters);
|
||||
|
||||
return json(result);
|
||||
} catch (error: any) {
|
||||
console.error('Failed to get schedule executions:', error);
|
||||
return json({ error: error.message }, { status: 500 });
|
||||
}
|
||||
};
|
||||
45
routes/api/schedules/executions/[id]/+server.ts
Normal file
45
routes/api/schedules/executions/[id]/+server.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Schedule Execution Detail API
|
||||
*
|
||||
* GET /api/schedules/executions/[id] - Returns execution details including logs
|
||||
* DELETE /api/schedules/executions/[id] - Delete a schedule execution
|
||||
*/
|
||||
|
||||
import { json } from '@sveltejs/kit';
|
||||
import type { RequestHandler } from './$types';
|
||||
import { getScheduleExecution, deleteScheduleExecution } from '$lib/server/db';
|
||||
|
||||
export const GET: RequestHandler = async ({ params }) => {
|
||||
try {
|
||||
const id = parseInt(params.id, 10);
|
||||
if (isNaN(id)) {
|
||||
return json({ error: 'Invalid execution ID' }, { status: 400 });
|
||||
}
|
||||
|
||||
const execution = await getScheduleExecution(id);
|
||||
if (!execution) {
|
||||
return json({ error: 'Execution not found' }, { status: 404 });
|
||||
}
|
||||
|
||||
return json(execution);
|
||||
} catch (error: any) {
|
||||
console.error('Failed to get schedule execution:', error);
|
||||
return json({ error: error.message }, { status: 500 });
|
||||
}
|
||||
};
|
||||
|
||||
export const DELETE: RequestHandler = async ({ params }) => {
|
||||
try {
|
||||
const id = parseInt(params.id, 10);
|
||||
if (isNaN(id)) {
|
||||
return json({ error: 'Invalid execution ID' }, { status: 400 });
|
||||
}
|
||||
|
||||
await deleteScheduleExecution(id);
|
||||
|
||||
return json({ success: true });
|
||||
} catch (error: any) {
|
||||
console.error('Failed to delete schedule execution:', error);
|
||||
return json({ error: error.message }, { status: 500 });
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user