From cef534ed53e4518fe0acf581bfe880788d42fc36 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 26 Dec 2018 10:36:24 +0100 Subject: Add user notification base code --- shared/utils/server/jobs.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'shared/utils/server') 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) { else servers = serversArg as ServerInfo[] const states: JobState[] = [ 'waiting', 'active', 'delayed' ] - const tasks: Promise[] = [] - let pendingRequests: boolean + let pendingRequests = false - do { + function tasksBuilder () { + const tasks: Promise[] = [] pendingRequests = false // Check if each server has pending request @@ -54,13 +54,16 @@ async function waitJobs (serversArg: ServerInfo[] | ServerInfo) { } } - await Promise.all(tasks) + return tasks + } + + do { + await Promise.all(tasksBuilder()) // Retry, in case of new jobs were created if (pendingRequests === false) { await wait(2000) - - await Promise.all(tasks) + await Promise.all(tasksBuilder()) } if (pendingRequests) { -- cgit v1.2.3