diff options
author | Chocobozzz <me@florianbigard.com> | 2023-04-21 15:00:01 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2023-05-09 08:57:34 +0200 |
commit | d102de1b38f2877463529c3b27bd35ffef4fd8bf (patch) | |
tree | 31fa0bdf26ad7a2ee46d600d804a6f03260266c8 /shared/server-commands/server/jobs.ts | |
parent | 2fe978744e5b74eb824e4d79c1bb9b840169f125 (diff) | |
download | PeerTube-d102de1b38f2877463529c3b27bd35ffef4fd8bf.tar.gz PeerTube-d102de1b38f2877463529c3b27bd35ffef4fd8bf.tar.zst PeerTube-d102de1b38f2877463529c3b27bd35ffef4fd8bf.zip |
Add runner server tests
Diffstat (limited to 'shared/server-commands/server/jobs.ts')
-rw-r--r-- | shared/server-commands/server/jobs.ts | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/shared/server-commands/server/jobs.ts b/shared/server-commands/server/jobs.ts index e1d6cdff4..ff3098063 100644 --- a/shared/server-commands/server/jobs.ts +++ b/shared/server-commands/server/jobs.ts | |||
@@ -1,16 +1,17 @@ | |||
1 | 1 | ||
2 | import { expect } from 'chai' | 2 | import { expect } from 'chai' |
3 | import { wait } from '@shared/core-utils' | 3 | import { wait } from '@shared/core-utils' |
4 | import { JobState, JobType } from '../../models' | 4 | import { JobState, JobType, RunnerJobState } from '../../models' |
5 | import { PeerTubeServer } from './server' | 5 | import { PeerTubeServer } from './server' |
6 | 6 | ||
7 | async function waitJobs ( | 7 | async function waitJobs ( |
8 | serversArg: PeerTubeServer[] | PeerTubeServer, | 8 | serversArg: PeerTubeServer[] | PeerTubeServer, |
9 | options: { | 9 | options: { |
10 | skipDelayed?: boolean // default false | 10 | skipDelayed?: boolean // default false |
11 | runnerJobs?: boolean // default false | ||
11 | } = {} | 12 | } = {} |
12 | ) { | 13 | ) { |
13 | const { skipDelayed = false } = options | 14 | const { skipDelayed = false, runnerJobs = false } = options |
14 | 15 | ||
15 | const pendingJobWait = process.env.NODE_PENDING_JOB_WAIT | 16 | const pendingJobWait = process.env.NODE_PENDING_JOB_WAIT |
16 | ? parseInt(process.env.NODE_PENDING_JOB_WAIT, 10) | 17 | ? parseInt(process.env.NODE_PENDING_JOB_WAIT, 10) |
@@ -33,7 +34,8 @@ async function waitJobs ( | |||
33 | // Check if each server has pending request | 34 | // Check if each server has pending request |
34 | for (const server of servers) { | 35 | for (const server of servers) { |
35 | for (const state of states) { | 36 | for (const state of states) { |
36 | const p = server.jobs.list({ | 37 | |
38 | const jobPromise = server.jobs.list({ | ||
37 | state, | 39 | state, |
38 | start: 0, | 40 | start: 0, |
39 | count: 10, | 41 | count: 10, |
@@ -46,17 +48,29 @@ async function waitJobs ( | |||
46 | } | 48 | } |
47 | }) | 49 | }) |
48 | 50 | ||
49 | tasks.push(p) | 51 | tasks.push(jobPromise) |
50 | } | 52 | } |
51 | 53 | ||
52 | const p = server.debug.getDebug() | 54 | const debugPromise = server.debug.getDebug() |
53 | .then(obj => { | 55 | .then(obj => { |
54 | if (obj.activityPubMessagesWaiting !== 0) { | 56 | if (obj.activityPubMessagesWaiting !== 0) { |
55 | pendingRequests = true | 57 | pendingRequests = true |
56 | } | 58 | } |
57 | }) | 59 | }) |
60 | tasks.push(debugPromise) | ||
61 | |||
62 | if (runnerJobs) { | ||
63 | const runnerJobsPromise = server.runnerJobs.list({ count: 100 }) | ||
64 | .then(({ data }) => { | ||
65 | for (const job of data) { | ||
66 | if (job.state.id !== RunnerJobState.COMPLETED) { | ||
67 | pendingRequests = true | ||
68 | } | ||
69 | } | ||
70 | }) | ||
71 | tasks.push(runnerJobsPromise) | ||
72 | } | ||
58 | 73 | ||
59 | tasks.push(p) | ||
60 | } | 74 | } |
61 | 75 | ||
62 | return tasks | 76 | return tasks |