diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-07 09:34:56 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-20 15:27:17 +0200 |
commit | 9c6327f803aaf4200672f1fc40b2f43786daca47 (patch) | |
tree | 962b975a5c3515804ed5d269019ce0aa3f5da6b3 /shared/extra-utils/server/jobs-command.ts | |
parent | c3d29f694bf8c910f917be655626d0f80871124f (diff) | |
download | PeerTube-9c6327f803aaf4200672f1fc40b2f43786daca47.tar.gz PeerTube-9c6327f803aaf4200672f1fc40b2f43786daca47.tar.zst PeerTube-9c6327f803aaf4200672f1fc40b2f43786daca47.zip |
Introduce jobs command
Diffstat (limited to 'shared/extra-utils/server/jobs-command.ts')
-rw-r--r-- | shared/extra-utils/server/jobs-command.ts | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/shared/extra-utils/server/jobs-command.ts b/shared/extra-utils/server/jobs-command.ts new file mode 100644 index 000000000..758b4a4af --- /dev/null +++ b/shared/extra-utils/server/jobs-command.ts | |||
@@ -0,0 +1,35 @@ | |||
1 | import { pick } from 'lodash' | ||
2 | import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' | ||
3 | import { Job, JobState, JobType, ResultList } from '../../models' | ||
4 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
5 | |||
6 | export class JobsCommand extends AbstractCommand { | ||
7 | |||
8 | getJobsList (options: OverrideCommandOptions & { | ||
9 | state?: JobState | ||
10 | jobType?: JobType | ||
11 | start?: number | ||
12 | count?: number | ||
13 | sort?: string | ||
14 | } = {}) { | ||
15 | const path = this.buildJobsUrl(options.state) | ||
16 | |||
17 | const query = pick(options, [ 'start', 'count', 'sort', 'jobType' ]) | ||
18 | |||
19 | return this.getRequestBody<ResultList<Job>>({ | ||
20 | ...options, | ||
21 | |||
22 | path, | ||
23 | query, | ||
24 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
25 | }) | ||
26 | } | ||
27 | |||
28 | private buildJobsUrl (state?: JobState) { | ||
29 | let path = '/api/v1/jobs' | ||
30 | |||
31 | if (state) path += '/' + state | ||
32 | |||
33 | return path | ||
34 | } | ||
35 | } | ||