diff options
Diffstat (limited to 'shared/extra-utils/server/jobs-command.ts')
-rw-r--r-- | shared/extra-utils/server/jobs-command.ts | 61 |
1 files changed, 0 insertions, 61 deletions
diff --git a/shared/extra-utils/server/jobs-command.ts b/shared/extra-utils/server/jobs-command.ts deleted file mode 100644 index 6636e7e4d..000000000 --- a/shared/extra-utils/server/jobs-command.ts +++ /dev/null | |||
@@ -1,61 +0,0 @@ | |||
1 | import { pick } from '@shared/core-utils' | ||
2 | import { HttpStatusCode } from '@shared/models' | ||
3 | import { Job, JobState, JobType, ResultList } from '../../models' | ||
4 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
5 | |||
6 | export class JobsCommand extends AbstractCommand { | ||
7 | |||
8 | async getLatest (options: OverrideCommandOptions & { | ||
9 | jobType: JobType | ||
10 | }) { | ||
11 | const { data } = await this.list({ ...options, start: 0, count: 1, sort: '-createdAt' }) | ||
12 | |||
13 | if (data.length === 0) return undefined | ||
14 | |||
15 | return data[0] | ||
16 | } | ||
17 | |||
18 | list (options: OverrideCommandOptions & { | ||
19 | state?: JobState | ||
20 | jobType?: JobType | ||
21 | start?: number | ||
22 | count?: number | ||
23 | sort?: string | ||
24 | } = {}) { | ||
25 | const path = this.buildJobsUrl(options.state) | ||
26 | |||
27 | const query = pick(options, [ 'start', 'count', 'sort', 'jobType' ]) | ||
28 | |||
29 | return this.getRequestBody<ResultList<Job>>({ | ||
30 | ...options, | ||
31 | |||
32 | path, | ||
33 | query, | ||
34 | implicitToken: true, | ||
35 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
36 | }) | ||
37 | } | ||
38 | |||
39 | listFailed (options: OverrideCommandOptions & { | ||
40 | jobType?: JobType | ||
41 | }) { | ||
42 | const path = this.buildJobsUrl('failed') | ||
43 | |||
44 | return this.getRequestBody<ResultList<Job>>({ | ||
45 | ...options, | ||
46 | |||
47 | path, | ||
48 | query: { start: 0, count: 50 }, | ||
49 | implicitToken: true, | ||
50 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
51 | }) | ||
52 | } | ||
53 | |||
54 | private buildJobsUrl (state?: JobState) { | ||
55 | let path = '/api/v1/jobs' | ||
56 | |||
57 | if (state) path += '/' + state | ||
58 | |||
59 | return path | ||
60 | } | ||
61 | } | ||