From b8b1188a140fc821c49c1f7e6a07a8338345bfa3 Mon Sep 17 00:00:00 2001 From: Travis Glenn Hansen Date: Wed, 25 Oct 2023 16:40:13 -0400 Subject: [PATCH] throw error immediately when waiting for job instead of after making api requests Signed-off-by: Travis Glenn Hansen --- src/driver/freenas/http/api.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/driver/freenas/http/api.js b/src/driver/freenas/http/api.js index e5e378f..5c4d335 100644 --- a/src/driver/freenas/http/api.js +++ b/src/driver/freenas/http/api.js @@ -698,15 +698,16 @@ class Api { // wait for job to finish do { + currentTime = Date.now() / 1000; + if (timeout > 0 && currentTime > startTime + timeout) { + throw new Error("timeout waiting for job to complete"); + } + if (job) { await sleep(check_interval); } job = await this.CoreGetJobs({ id: job_id }); job = job[0]; - currentTime = Date.now() / 1000; - if (timeout > 0 && currentTime > startTime + timeout) { - throw new Error("timeout waiting for job to complete"); - } } while (!["SUCCESS", "ABORTED", "FAILED"].includes(job.state)); return job;