From 0cf102a1598635383d64aa4c6247a405840c58b5 Mon Sep 17 00:00:00 2001 From: lathoub <4082369+lathoub@users.noreply.github.com> Date: Sun, 1 Sep 2024 11:51:04 +0200 Subject: [PATCH] delete job according to spec --- src/controllers/processes/job.js | 2 +- src/models/processes/job.js | 65 ++++++++++++++++++++++++-------- 2 files changed, 50 insertions(+), 17 deletions(-) diff --git a/src/controllers/processes/job.js b/src/controllers/processes/job.js index 39a56f6..2cfa139 100644 --- a/src/controllers/processes/job.js +++ b/src/controllers/processes/job.js @@ -74,7 +74,7 @@ export function delete_ (req, res) { return } - res.status(204).end(); + res.status(200).json(content); }) } diff --git a/src/models/processes/job.js b/src/models/processes/job.js index 0f58f46..adb306d 100644 --- a/src/models/processes/job.js +++ b/src/models/processes/job.js @@ -12,14 +12,14 @@ function getLinks(neutralUrl, format, jobId, links) { } links.push({ - href: urlJoin(neutralUrl, 'results', `?f=${format}`), + href: urlJoin(neutralUrl, "results", `?f=${format}`), rel: `http://www.opengis.net/def/rel/ogc/1.0/results`, type: getTypeFromFormat(format), title: `Results of job as ${format}`, }); utils.getAlternateFormats(format, ["json", "html"]).forEach((altFormat) => { links.push({ - href: urlJoin(neutralUrl, 'results', `?f=${altFormat}`), + href: urlJoin(neutralUrl, "results", `?f=${altFormat}`), rel: `http://www.opengis.net/def/rel/ogc/1.0/results`, type: getTypeFromFormat(altFormat), title: `Results of job as ${altFormat}`, @@ -29,11 +29,11 @@ function getLinks(neutralUrl, format, jobId, links) { export function getContent(neutralUrl, format, jobId, job) { var content = structuredClone(job); - content.links = [] - + content.links = []; + getLinks(neutralUrl, format, jobId, content.links); - delete content.results + delete content.results; return content; } @@ -79,14 +79,20 @@ export function execute(path, process, job, isAsync, parameters, callback) { try { import(path) .then((module) => { - module.launch(process, job, isAsync, parameters, function (err, content) { - if (err) { - callback(err, undefined); - return; + module.launch( + process, + job, + isAsync, + parameters, + function (err, content) { + if (err) { + callback(err, undefined); + return; + } + + callback(undefined, content); } - - callback(undefined, content); - }); + ); }) .catch((error) => { return callback( @@ -103,23 +109,50 @@ export function execute(path, process, job, isAsync, parameters, callback) { } } +/** + * Description placeholder + * + * @param {*} neutralUrl + * @param {*} format + * @param {*} jobId + * @param {*} callback + * @returns {*} + */ function delete_(neutralUrl, format, jobId, callback) { - var jobs = getJobs(); var job = jobs[jobId]; if (!job) return callback( { httpCode: 404, - code: `Job not found: ${jobId}`, + code: `No such job: ${jobId}`, description: "Make sure you use an existing jobId. See /Jobs", }, undefined ); - delete jobs[jobId] + let jobsUrl = neutralUrl.substr( + 0, + neutralUrl.lastIndexOf("/jobs") + "/jobs".length + ); + + let content = job; + content.status = "dismissed"; + content.message = "Job dismissed"; + content.updated = new Date().toISOString(); + content.links = []; + content.links.push({ + href: jobsUrl, + rel: `up`, + type: "application/json", + title: `The job list for the current process`, + }); + + delete content.results; - return callback(undefined, {}); + delete jobs[jobId]; + + return callback(undefined, content); } export default {