diff options
Diffstat (limited to 'shared/utils/server/jobs.ts')
-rw-r--r-- | shared/utils/server/jobs.ts | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/shared/utils/server/jobs.ts b/shared/utils/server/jobs.ts index f4623f896..6218c0b66 100644 --- a/shared/utils/server/jobs.ts +++ b/shared/utils/server/jobs.ts | |||
@@ -35,10 +35,10 @@ async function waitJobs (serversArg: ServerInfo[] | ServerInfo) { | |||
35 | else servers = serversArg as ServerInfo[] | 35 | else servers = serversArg as ServerInfo[] |
36 | 36 | ||
37 | const states: JobState[] = [ 'waiting', 'active', 'delayed' ] | 37 | const states: JobState[] = [ 'waiting', 'active', 'delayed' ] |
38 | const tasks: Promise<any>[] = [] | 38 | let pendingRequests = false |
39 | let pendingRequests: boolean | ||
40 | 39 | ||
41 | do { | 40 | function tasksBuilder () { |
41 | const tasks: Promise<any>[] = [] | ||
42 | pendingRequests = false | 42 | pendingRequests = false |
43 | 43 | ||
44 | // Check if each server has pending request | 44 | // Check if each server has pending request |
@@ -54,13 +54,16 @@ async function waitJobs (serversArg: ServerInfo[] | ServerInfo) { | |||
54 | } | 54 | } |
55 | } | 55 | } |
56 | 56 | ||
57 | await Promise.all(tasks) | 57 | return tasks |
58 | } | ||
59 | |||
60 | do { | ||
61 | await Promise.all(tasksBuilder()) | ||
58 | 62 | ||
59 | // Retry, in case of new jobs were created | 63 | // Retry, in case of new jobs were created |
60 | if (pendingRequests === false) { | 64 | if (pendingRequests === false) { |
61 | await wait(2000) | 65 | await wait(2000) |
62 | 66 | await Promise.all(tasksBuilder()) | |
63 | await Promise.all(tasks) | ||
64 | } | 67 | } |
65 | 68 | ||
66 | if (pendingRequests) { | 69 | if (pendingRequests) { |