Skip to content

Instantly share code, notes, and snippets.

@barisere
Last active September 27, 2018 13:03
Show Gist options
  • Save barisere/caec5970fa3faf6900302eed017599a9 to your computer and use it in GitHub Desktop.
Save barisere/caec5970fa3faf6900302eed017599a9 to your computer and use it in GitHub Desktop.
// file resource-controllers.js
const { makeWorker, cancelJob } = require("./undo-queue");
async function deleteResource (/* parameters */) {
// code to delete the resource
}
const scheduleResourceDeletion = makeWorker(deleteResource);
exports.delete = function (req, res, next) {
const id = req.params.id;
// get other request data as necessary
scheduleResourceDeletion(id /* other arguments */)
.then(jobId => res.status(200).json({ jobId }).end())
.catch(next);
};
exports.cancelDelete = function (req, res, next) {
const jobId = req.query.id;
cancelJob(jobId)
.then(success => res.status(200).json({ success }).end())
.catch(next);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment