Skip to content

Commit

Permalink
delete job according to spec
Browse files Browse the repository at this point in the history
  • Loading branch information
lathoub committed Sep 1, 2024
1 parent e3558ca commit 0cf102a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/controllers/processes/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export function delete_ (req, res) {
return
}

res.status(204).end();
res.status(200).json(content);
})

}
65 changes: 49 additions & 16 deletions src/models/processes/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
Expand All @@ -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;
}
Expand Down Expand Up @@ -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(
Expand All @@ -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 {
Expand Down

0 comments on commit 0cf102a

Please sign in to comment.