1 import { pick } from '@shared/core-utils'
2 import { HttpStatusCode, Job, JobState, JobType, ResultList } from '@shared/models'
3 import { AbstractCommand, OverrideCommandOptions } from '../shared'
5 export class JobsCommand extends AbstractCommand {
7 async getLatest (options: OverrideCommandOptions & {
10 const { data } = await this.list({ ...options, start: 0, count: 1, sort: '-createdAt' })
12 if (data.length === 0) return undefined
17 pauseJobQueue (options: OverrideCommandOptions = {}) {
18 const path = '/api/v1/jobs/pause'
20 return this.postBodyRequest({
25 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
29 resumeJobQueue (options: OverrideCommandOptions = {}) {
30 const path = '/api/v1/jobs/resume'
32 return this.postBodyRequest({
37 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
41 list (options: OverrideCommandOptions & {
48 const path = this.buildJobsUrl(options.state)
50 const query = pick(options, [ 'start', 'count', 'sort', 'jobType' ])
52 return this.getRequestBody<ResultList<Job>>({
58 defaultExpectedStatus: HttpStatusCode.OK_200
62 listFailed (options: OverrideCommandOptions & {
65 const path = this.buildJobsUrl('failed')
67 return this.getRequestBody<ResultList<Job>>({
71 query: { start: 0, count: 50 },
73 defaultExpectedStatus: HttpStatusCode.OK_200
77 private buildJobsUrl (state?: JobState) {
78 let path = '/api/v1/jobs'
80 if (state) path += '/' + state