| 1 | import type { FlaskBaseResponse } from "@/types/flask.d" |
| 2 | import type { Job } from "@/types/scheduler.d" |
| 3 | import { HttpClient } from "../httpClient" |
| 4 | |
| 5 | export interface UpdateJobPayload { |
| 6 | /** minutes */ |
| 7 | time_interval: number |
| 8 | extra_data: string |
| 9 | } |
| 10 | |
| 11 | export default { |
| 12 | getAllJobs() { |
| 13 | return HttpClient.get<FlaskBaseResponse & { jobs: Job[] }>(`/scheduler`) |
| 14 | }, |
| 15 | getNextRun(job_id: string) { |
| 16 | return HttpClient.get<FlaskBaseResponse & { next_run_time: Date }>(`/scheduler/next_run/${job_id}`) |
| 17 | }, |
| 18 | jobAction(job_id: string, action: "run" | "start" | "pause") { |
| 19 | const endpoint = action === "run" ? "jobs/run" : action |
| 20 | return HttpClient.post<FlaskBaseResponse>(`/scheduler/${endpoint}/${job_id}`) |
| 21 | }, |
| 22 | updateJob(job_id: string, payload: UpdateJobPayload) { |
| 23 | return HttpClient.put<FlaskBaseResponse>(`/scheduler/update/${job_id}`, {}, { params: payload }) |
| 24 | } |
| 25 | } |