aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-12-04 14:49:59 +0100
committerChocobozzz <me@florianbigard.com>2019-12-04 14:49:59 +0100
commit1061c73fde3005100ead8764eacb444f240440d6 (patch)
tree0a548d7f0a9a548a52adf6d702dd589b04cd5ab0 /shared
parent44df5c755c31798e64eba1ec41dd7e2d7ef50e56 (diff)
downloadPeerTube-1061c73fde3005100ead8764eacb444f240440d6.tar.gz
PeerTube-1061c73fde3005100ead8764eacb444f240440d6.tar.zst
PeerTube-1061c73fde3005100ead8764eacb444f240440d6.zip
Add ability to filter per job type
Diffstat (limited to 'shared')
-rw-r--r--shared/extra-utils/server/jobs.ts46
-rw-r--r--shared/models/server/job.model.ts6
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 @@
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 => {
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}