aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/server/jobs.ts
diff options
context:
space:
mode:
Diffstat (limited to 'shared/extra-utils/server/jobs.ts')
-rw-r--r--shared/extra-utils/server/jobs.ts46
1 files changed, 34 insertions, 12 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 @@
1import * as request from 'supertest' 1import * as request from 'supertest'
2import { Job, JobState } from '../../models' 2import { Job, JobState, JobType } from '../../models'
3import { wait } from '../miscs/miscs' 3import { wait } from '../miscs/miscs'
4import { ServerInfo } from './servers' 4import { ServerInfo } from './servers'
5import { makeGetRequest } from '@shared/extra-utils'
5 6
6function getJobsList (url: string, accessToken: string, state: JobState) { 7function 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
17function getJobsListPaginationAndSort (url: string, accessToken: string, state: JobState, start: number, count: number, sort: string) { 18function 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
31async function waitJobs (serversArg: ServerInfo[] | ServerInfo) { 46async 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 => {