diff options
author | Chocobozzz <me@florianbigard.com> | 2021-12-17 09:29:23 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-12-17 09:29:23 +0100 |
commit | bf54587a3e2ad9c2c186828f2a5682b91ee2cc00 (patch) | |
tree | 54b40aaf01bae210632473285c3c7571d51e4f89 /shared/extra-utils/server/jobs-command.ts | |
parent | 6b5f72beda96d8b7e4d6329c4001827334de27dd (diff) | |
download | PeerTube-bf54587a3e2ad9c2c186828f2a5682b91ee2cc00.tar.gz PeerTube-bf54587a3e2ad9c2c186828f2a5682b91ee2cc00.tar.zst PeerTube-bf54587a3e2ad9c2c186828f2a5682b91ee2cc00.zip |
shared/ typescript types dir server-commands
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 | } | ||