2020-02-08 23:23:08 +00:00
|
|
|
import http from '@/api/http';
|
|
|
|
|
|
|
|
export interface Schedule {
|
|
|
|
id: number;
|
|
|
|
name: string;
|
|
|
|
cron: {
|
|
|
|
dayOfWeek: string;
|
2021-01-17 03:07:39 +00:00
|
|
|
month: string;
|
2020-02-08 23:23:08 +00:00
|
|
|
dayOfMonth: string;
|
|
|
|
hour: string;
|
|
|
|
minute: string;
|
|
|
|
};
|
|
|
|
isActive: boolean;
|
|
|
|
isProcessing: boolean;
|
|
|
|
lastRunAt: Date | null;
|
|
|
|
nextRunAt: Date | null;
|
|
|
|
createdAt: Date;
|
|
|
|
updatedAt: Date;
|
|
|
|
|
|
|
|
tasks: Task[];
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface Task {
|
|
|
|
id: number;
|
|
|
|
sequenceId: number;
|
|
|
|
action: string;
|
|
|
|
payload: string;
|
|
|
|
timeOffset: number;
|
|
|
|
isQueued: boolean;
|
|
|
|
createdAt: Date;
|
|
|
|
updatedAt: Date;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const rawDataToServerTask = (data: any): Task => ({
|
|
|
|
id: data.id,
|
|
|
|
sequenceId: data.sequence_id,
|
|
|
|
action: data.action,
|
|
|
|
payload: data.payload,
|
|
|
|
timeOffset: data.time_offset,
|
|
|
|
isQueued: data.is_queued,
|
|
|
|
createdAt: new Date(data.created_at),
|
|
|
|
updatedAt: new Date(data.updated_at),
|
|
|
|
});
|
|
|
|
|
|
|
|
export const rawDataToServerSchedule = (data: any): Schedule => ({
|
|
|
|
id: data.id,
|
|
|
|
name: data.name,
|
|
|
|
cron: {
|
|
|
|
dayOfWeek: data.cron.day_of_week,
|
2021-01-17 03:07:39 +00:00
|
|
|
month: data.cron.month,
|
2020-02-08 23:23:08 +00:00
|
|
|
dayOfMonth: data.cron.day_of_month,
|
|
|
|
hour: data.cron.hour,
|
|
|
|
minute: data.cron.minute,
|
|
|
|
},
|
|
|
|
isActive: data.is_active,
|
|
|
|
isProcessing: data.is_processing,
|
|
|
|
lastRunAt: data.last_run_at ? new Date(data.last_run_at) : null,
|
|
|
|
nextRunAt: data.next_run_at ? new Date(data.next_run_at) : null,
|
|
|
|
createdAt: new Date(data.created_at),
|
|
|
|
updatedAt: new Date(data.updated_at),
|
|
|
|
|
|
|
|
tasks: (data.relationships?.tasks?.data || []).map((row: any) => rawDataToServerTask(row.attributes)),
|
|
|
|
});
|
|
|
|
|
|
|
|
export default (uuid: string): Promise<Schedule[]> => {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
http.get(`/api/client/servers/${uuid}/schedules`, {
|
|
|
|
params: {
|
2020-07-05 01:30:50 +00:00
|
|
|
include: [ 'tasks' ],
|
2020-02-08 23:23:08 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
.then(({ data }) => resolve((data.data || []).map((row: any) => rawDataToServerSchedule(row.attributes))))
|
|
|
|
.catch(reject);
|
|
|
|
});
|
|
|
|
};
|