From 2c1745ce2854847cda42c10966c68cc6069fead5 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Wed, 8 Sep 2021 14:17:27 -0400 Subject: [PATCH] Refactor checkJobStatus() to use API URLs provided via context --- netbox/project-static/dist/jobs.js | Bin 108704 -> 108677 bytes netbox/project-static/dist/jobs.js.map | Bin 105851 -> 105846 bytes netbox/project-static/src/jobs.ts | 23 +++++++++++---------- netbox/templates/extras/report_result.html | 2 +- netbox/templates/extras/script_result.html | 2 +- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/netbox/project-static/dist/jobs.js b/netbox/project-static/dist/jobs.js index 221d48d56d61faa9c7c55a7c81f7213b93648add..2aedf1219487eaf56a9ed4964b409d5cacc6cdd8 100644 GIT binary patch delta 47 ycmZ2*k*)P2Tf-K{&5M{zi*lxKUBnm#Vr&;&%$Uu{m^pp+62`Y+fv%;DV$1;C{SvPL delta 74 zcmZp@$hP1jTf-K{&5M{aQ>JfQ#25vnw+k<3%x08N&`&JL)K9G_DM~EX&&p5IElMpe b%_%9?SE diff --git a/netbox/project-static/dist/jobs.js.map b/netbox/project-static/dist/jobs.js.map index f549c87af97236f2654eebd365bc90bf0c7ed54d..d7c1dbcbfc6b9c18c6f689a247de6a1e4800bccc 100644 GIT binary patch delta 189 zcmeypi|yMkwuUW?+h!@bhv>LEI{NCkJ31!oq&qo!7C3Nq<(g3NZ!nXWLGF$@4y CJ2ede diff --git a/netbox/project-static/src/jobs.ts b/netbox/project-static/src/jobs.ts index 8a8a3fd12..dedf0706d 100644 --- a/netbox/project-static/src/jobs.ts +++ b/netbox/project-static/src/jobs.ts @@ -4,7 +4,7 @@ import { apiGetBase, hasError, getNetboxData } from './util'; let timeout: number = 1000; interface JobInfo { - id: Nullable; + url: Nullable; complete: boolean; } @@ -23,15 +23,16 @@ function asyncTimeout(ms: number) { function getJobInfo(): JobInfo { let complete = false; - const id = getNetboxData('data-job-id'); - const jobComplete = getNetboxData('data-job-complete'); + // Determine the API URL for the job status + const url = getNetboxData('data-job-url'); // Determine the job completion status, if present. If the job is not complete, the value will be // "None". Otherwise, it will be a stringified date. + const jobComplete = getNetboxData('data-job-complete'); if (typeof jobComplete === 'string' && jobComplete.toLowerCase() !== 'none') { complete = true; } - return { id, complete }; + return { url, complete }; } /** @@ -59,10 +60,10 @@ function updateLabel(status: JobStatus) { /** * Recursively check the job's status. - * @param id Job ID + * @param url API URL for job result */ -async function checkJobStatus(id: string) { - const res = await apiGetBase(`/api/extras/job-results/${id}/`); +async function checkJobStatus(url: string) { + const res = await apiGetBase(url); if (hasError(res)) { // If the response is an API error, display an error message and stop checking for job status. const toast = createToast('danger', 'Error', res.error); @@ -82,17 +83,17 @@ async function checkJobStatus(id: string) { if (timeout < 10000) { timeout += 1000; } - await Promise.all([checkJobStatus(id), asyncTimeout(timeout)]); + await Promise.all([checkJobStatus(url), asyncTimeout(timeout)]); } } } function initJobs() { - const { id, complete } = getJobInfo(); + const { url, complete } = getJobInfo(); - if (id !== null && !complete) { + if (url !== null && !complete) { // If there is a job ID and it is not completed, check for the job's status. - Promise.resolve(checkJobStatus(id)); + Promise.resolve(checkJobStatus(url)); } } diff --git a/netbox/templates/extras/report_result.html b/netbox/templates/extras/report_result.html index 1f757d4cb..f8da50e8e 100644 --- a/netbox/templates/extras/report_result.html +++ b/netbox/templates/extras/report_result.html @@ -96,6 +96,6 @@ {% endblock %} {% block data %} - + {% endblock %} diff --git a/netbox/templates/extras/script_result.html b/netbox/templates/extras/script_result.html index 59ca8a69d..f463b0f2c 100644 --- a/netbox/templates/extras/script_result.html +++ b/netbox/templates/extras/script_result.html @@ -112,6 +112,6 @@ {% endblock content-wrapper %} {% block data %} - + {% endblock %}