diff options
Diffstat (limited to 'shared/extra-utils/server')
-rw-r--r-- | shared/extra-utils/server/debug.ts | 19 | ||||
-rw-r--r-- | shared/extra-utils/server/jobs.ts | 23 |
2 files changed, 37 insertions, 5 deletions
diff --git a/shared/extra-utils/server/debug.ts b/shared/extra-utils/server/debug.ts new file mode 100644 index 000000000..5cf80a5fb --- /dev/null +++ b/shared/extra-utils/server/debug.ts | |||
@@ -0,0 +1,19 @@ | |||
1 | import { makeGetRequest } from '../requests/requests' | ||
2 | import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' | ||
3 | |||
4 | function getDebug (url: string, token: string) { | ||
5 | const path = '/api/v1/server/debug' | ||
6 | |||
7 | return makeGetRequest({ | ||
8 | url, | ||
9 | path, | ||
10 | token, | ||
11 | statusCodeExpected: HttpStatusCode.OK_200 | ||
12 | }) | ||
13 | } | ||
14 | |||
15 | // --------------------------------------------------------------------------- | ||
16 | |||
17 | export { | ||
18 | getDebug | ||
19 | } | ||
diff --git a/shared/extra-utils/server/jobs.ts b/shared/extra-utils/server/jobs.ts index a53749589..97971f960 100644 --- a/shared/extra-utils/server/jobs.ts +++ b/shared/extra-utils/server/jobs.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import * as request from 'supertest' | 1 | import * as request from 'supertest' |
2 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | 2 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' |
3 | import { makeGetRequest } from '../../../shared/extra-utils' | 3 | import { getDebug, makeGetRequest } from '../../../shared/extra-utils' |
4 | import { Job, JobState, JobType } from '../../models' | 4 | import { Job, JobState, JobType, ServerDebug } from '../../models' |
5 | import { wait } from '../miscs/miscs' | 5 | import { wait } from '../miscs/miscs' |
6 | import { ServerInfo } from './servers' | 6 | import { ServerInfo } from './servers' |
7 | 7 | ||
@@ -53,7 +53,10 @@ function getJobsListPaginationAndSort (options: { | |||
53 | } | 53 | } |
54 | 54 | ||
55 | async function waitJobs (serversArg: ServerInfo[] | ServerInfo) { | 55 | async function waitJobs (serversArg: ServerInfo[] | ServerInfo) { |
56 | const pendingJobWait = process.env.NODE_PENDING_JOB_WAIT ? parseInt(process.env.NODE_PENDING_JOB_WAIT, 10) : 2000 | 56 | const pendingJobWait = process.env.NODE_PENDING_JOB_WAIT |
57 | ? parseInt(process.env.NODE_PENDING_JOB_WAIT, 10) | ||
58 | : 500 | ||
59 | |||
57 | let servers: ServerInfo[] | 60 | let servers: ServerInfo[] |
58 | 61 | ||
59 | if (Array.isArray(serversArg) === false) servers = [ serversArg as ServerInfo ] | 62 | if (Array.isArray(serversArg) === false) servers = [ serversArg as ServerInfo ] |
@@ -75,16 +78,26 @@ async function waitJobs (serversArg: ServerInfo[] | ServerInfo) { | |||
75 | start: 0, | 78 | start: 0, |
76 | count: 10, | 79 | count: 10, |
77 | sort: '-createdAt' | 80 | sort: '-createdAt' |
78 | }) | 81 | }).then(res => res.body.data) |
79 | .then(res => res.body.data) | ||
80 | .then((jobs: Job[]) => jobs.filter(j => j.type !== 'videos-views')) | 82 | .then((jobs: Job[]) => jobs.filter(j => j.type !== 'videos-views')) |
81 | .then(jobs => { | 83 | .then(jobs => { |
82 | if (jobs.length !== 0) { | 84 | if (jobs.length !== 0) { |
83 | pendingRequests = true | 85 | pendingRequests = true |
84 | } | 86 | } |
85 | }) | 87 | }) |
88 | |||
86 | tasks.push(p) | 89 | tasks.push(p) |
87 | } | 90 | } |
91 | |||
92 | const p = getDebug(server.url, server.accessToken) | ||
93 | .then(res => res.body) | ||
94 | .then((obj: ServerDebug) => { | ||
95 | if (obj.activityPubMessagesWaiting !== 0) { | ||
96 | pendingRequests = true | ||
97 | } | ||
98 | }) | ||
99 | |||
100 | tasks.push(p) | ||
88 | } | 101 | } |
89 | 102 | ||
90 | return tasks | 103 | return tasks |