From 1061c73fde3005100ead8764eacb444f240440d6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 4 Dec 2019 14:49:59 +0100 Subject: Add ability to filter per job type --- shared/extra-utils/server/jobs.ts | 46 +++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 12 deletions(-) (limited to 'shared/extra-utils/server') 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 @@ import * as request from 'supertest' -import { Job, JobState } from '../../models' +import { Job, JobState, JobType } from '../../models' import { wait } from '../miscs/miscs' import { ServerInfo } from './servers' +import { makeGetRequest } from '@shared/extra-utils' function getJobsList (url: string, accessToken: string, state: JobState) { const path = '/api/v1/jobs/' + state @@ -14,18 +15,32 @@ function getJobsList (url: string, accessToken: string, state: JobState) { .expect('Content-Type', /json/) } -function getJobsListPaginationAndSort (url: string, accessToken: string, state: JobState, start: number, count: number, sort: string) { +function getJobsListPaginationAndSort (options: { + url: string, + accessToken: string, + state: JobState, + start: number, + count: number, + sort: string, + jobType?: JobType +}) { + const { url, accessToken, state, start, count, sort, jobType } = options const path = '/api/v1/jobs/' + state - return request(url) - .get(path) - .query({ start }) - .query({ count }) - .query({ sort }) - .set('Accept', 'application/json') - .set('Authorization', 'Bearer ' + accessToken) - .expect(200) - .expect('Content-Type', /json/) + const query = { + start, + count, + sort, + jobType + } + + return makeGetRequest({ + url, + path, + token: accessToken, + statusCodeExpected: 200, + query + }) } async function waitJobs (serversArg: ServerInfo[] | ServerInfo) { @@ -44,7 +59,14 @@ async function waitJobs (serversArg: ServerInfo[] | ServerInfo) { // Check if each server has pending request for (const server of servers) { for (const state of states) { - const p = getJobsListPaginationAndSort(server.url, server.accessToken, state, 0, 10, '-createdAt') + const p = getJobsListPaginationAndSort({ + url: server.url, + accessToken: server.accessToken, + state: state, + start: 0, + count: 10, + sort: '-createdAt' + }) .then(res => res.body.data) .then((jobs: Job[]) => jobs.filter(j => j.type !== 'videos-views')) .then(jobs => { -- cgit v1.2.3