diff options
Diffstat (limited to 'shared')
-rw-r--r-- | shared/extra-utils/server/jobs.ts | 46 | ||||
-rw-r--r-- | shared/models/server/job.model.ts | 6 |
2 files changed, 37 insertions, 15 deletions
diff --git a/shared/extra-utils/server/jobs.ts b/shared/extra-utils/server/jobs.ts index b3db885e8..cc1352e14 100644 --- a/shared/extra-utils/server/jobs.ts +++ b/shared/extra-utils/server/jobs.ts | |||
@@ -1,7 +1,8 @@ | |||
1 | import * as request from 'supertest' | 1 | import * as request from 'supertest' |
2 | import { Job, JobState } from '../../models' | 2 | import { Job, JobState, JobType } from '../../models' |
3 | import { wait } from '../miscs/miscs' | 3 | import { wait } from '../miscs/miscs' |
4 | import { ServerInfo } from './servers' | 4 | import { ServerInfo } from './servers' |
5 | import { makeGetRequest } from '@shared/extra-utils' | ||
5 | 6 | ||
6 | function getJobsList (url: string, accessToken: string, state: JobState) { | 7 | function getJobsList (url: string, accessToken: string, state: JobState) { |
7 | const path = '/api/v1/jobs/' + state | 8 | const path = '/api/v1/jobs/' + state |
@@ -14,18 +15,32 @@ function getJobsList (url: string, accessToken: string, state: JobState) { | |||
14 | .expect('Content-Type', /json/) | 15 | .expect('Content-Type', /json/) |
15 | } | 16 | } |
16 | 17 | ||
17 | function getJobsListPaginationAndSort (url: string, accessToken: string, state: JobState, start: number, count: number, sort: string) { | 18 | function getJobsListPaginationAndSort (options: { |
19 | url: string, | ||
20 | accessToken: string, | ||
21 | state: JobState, | ||
22 | start: number, | ||
23 | count: number, | ||
24 | sort: string, | ||
25 | jobType?: JobType | ||
26 | }) { | ||
27 | const { url, accessToken, state, start, count, sort, jobType } = options | ||
18 | const path = '/api/v1/jobs/' + state | 28 | const path = '/api/v1/jobs/' + state |
19 | 29 | ||
20 | return request(url) | 30 | const query = { |
21 | .get(path) | 31 | start, |
22 | .query({ start }) | 32 | count, |
23 | .query({ count }) | 33 | sort, |
24 | .query({ sort }) | 34 | jobType |
25 | .set('Accept', 'application/json') | 35 | } |
26 | .set('Authorization', 'Bearer ' + accessToken) | 36 | |
27 | .expect(200) | 37 | return makeGetRequest({ |
28 | .expect('Content-Type', /json/) | 38 | url, |
39 | path, | ||
40 | token: accessToken, | ||
41 | statusCodeExpected: 200, | ||
42 | query | ||
43 | }) | ||
29 | } | 44 | } |
30 | 45 | ||
31 | async function waitJobs (serversArg: ServerInfo[] | ServerInfo) { | 46 | async function waitJobs (serversArg: ServerInfo[] | ServerInfo) { |
@@ -44,7 +59,14 @@ async function waitJobs (serversArg: ServerInfo[] | ServerInfo) { | |||
44 | // Check if each server has pending request | 59 | // Check if each server has pending request |
45 | for (const server of servers) { | 60 | for (const server of servers) { |
46 | for (const state of states) { | 61 | for (const state of states) { |
47 | const p = getJobsListPaginationAndSort(server.url, server.accessToken, state, 0, 10, '-createdAt') | 62 | const p = getJobsListPaginationAndSort({ |
63 | url: server.url, | ||
64 | accessToken: server.accessToken, | ||
65 | state: state, | ||
66 | start: 0, | ||
67 | count: 10, | ||
68 | sort: '-createdAt' | ||
69 | }) | ||
48 | .then(res => res.body.data) | 70 | .then(res => res.body.data) |
49 | .then((jobs: Job[]) => jobs.filter(j => j.type !== 'videos-views')) | 71 | .then((jobs: Job[]) => jobs.filter(j => j.type !== 'videos-views')) |
50 | .then(jobs => { | 72 | .then(jobs => { |
diff --git a/shared/models/server/job.model.ts b/shared/models/server/job.model.ts index 1b9aa8a07..b82a633b2 100644 --- a/shared/models/server/job.model.ts +++ b/shared/models/server/job.model.ts | |||
@@ -17,7 +17,7 @@ export interface Job { | |||
17 | type: JobType | 17 | type: JobType |
18 | data: any, | 18 | data: any, |
19 | error: any, | 19 | error: any, |
20 | createdAt: Date | 20 | createdAt: Date | string |
21 | finishedOn: Date | 21 | finishedOn: Date | string |
22 | processedOn: Date | 22 | processedOn: Date | string |
23 | } | 23 | } |