Compare commits

...

2 Commits

@ -12,7 +12,7 @@ const chalk = require("chalk");
let argv = yargs.argv; let argv = yargs.argv;
let [ configurationPath, task, item ] = argv._; let [ configurationPath, task, item ] = argv._;
let absoluteConfigurationPath = path.join(process.cwd(), configurationPath); let absoluteConfigurationPath = path.resolve(process.cwd(), configurationPath);
let configuration = require(absoluteConfigurationPath); let configuration = require(absoluteConfigurationPath);
return Promise.try(() => { return Promise.try(() => {

@ -17,7 +17,7 @@ let configurationPath = argv._[0];
let listenHost = argv.listenHost ?? "127.0.0.1"; let listenHost = argv.listenHost ?? "127.0.0.1";
let listenPort = argv.listenPort ?? 3131; let listenPort = argv.listenPort ?? 3131;
let absoluteConfigurationPath = path.join(process.cwd(), configurationPath); let absoluteConfigurationPath = path.resolve(process.cwd(), configurationPath);
let configuration = require(absoluteConfigurationPath); let configuration = require(absoluteConfigurationPath);
return Promise.try(() => { return Promise.try(() => {

@ -38,7 +38,7 @@ let configurationPath = argv._[0];
let listenHost = argv.listenHost ?? "127.0.0.1"; let listenHost = argv.listenHost ?? "127.0.0.1";
let listenPort = argv.listenPort ?? 3000; let listenPort = argv.listenPort ?? 3000;
let absoluteConfigurationPath = path.join(process.cwd(), configurationPath); let absoluteConfigurationPath = path.resolve(process.cwd(), configurationPath);
let configuration = require(absoluteConfigurationPath); let configuration = require(absoluteConfigurationPath);
return Promise.try(() => { return Promise.try(() => {

@ -12,7 +12,7 @@ const chalk = require("chalk");
let argv = yargs.argv; let argv = yargs.argv;
let [ configurationPath, task, item ] = argv._; let [ configurationPath, task, item ] = argv._;
let absoluteConfigurationPath = path.join(process.cwd(), configurationPath); let absoluteConfigurationPath = path.resolve(process.cwd(), configurationPath);
let configuration = require(absoluteConfigurationPath); let configuration = require(absoluteConfigurationPath);
return Promise.try(() => { return Promise.try(() => {

@ -159,12 +159,13 @@ module.exports = function (state) {
}, },
forItem: function (_options) { forItem: function (_options) {
// FIXME: Proper validation rules here for the other fields as well // FIXME: Proper validation rules here for the other fields as well
let { item, task, mutationQueue, readTX, simulate } = validateOptions(arguments, { let { item, task, mutationQueue, readTX, simulate, onDeleteSelf } = validateOptions(arguments, {
item: anything, item: anything,
task: [ required, isTask ], task: [ required, isTask ],
mutationQueue: anything, mutationQueue: anything,
readTX: maybeTX, readTX: maybeTX,
simulate: anything simulate: anything,
onDeleteSelf: isFunction
}); });
// We create a new instance of the actual API for every item being processed. This is necessary because some of the input arguments will default to item-specific values, and some of the logic is dependent on task-specific metadata. This is a more efficient (and understandable) approach than pretending the API is stateless and then separately wrapping the API *again* for every individual item with a whole separate layer of input validation rules. // We create a new instance of the actual API for every item being processed. This is necessary because some of the input arguments will default to item-specific values, and some of the logic is dependent on task-specific metadata. This is a more efficient (and understandable) approach than pretending the API is stateless and then separately wrapping the API *again* for every individual item with a whole separate layer of input validation rules.
@ -261,6 +262,11 @@ module.exports = function (state) {
] ]
}); });
if (options.id === item.id) {
// This hook is necessary to allow the task kernel to skip certain operations in this case, eg. storing the task result - it would be redundant, and reference a now non-existent item.
onDeleteSelf();
}
return mutableOperation((tx) => { return mutableOperation((tx) => {
return backend.deleteItem(tx, options); return backend.deleteItem(tx, options);
}); });
@ -294,6 +300,7 @@ module.exports = function (state) {
updateData: function (_options) { updateData: function (_options) {
// NOTE: This is a semantically self-describing convenience wrapper for `storeItem` that updates the currently-being-processed item // NOTE: This is a semantically self-describing convenience wrapper for `storeItem` that updates the currently-being-processed item
// TODO: Have a dedicated alias and/or signature (for this function) for the common case of "just add a few attributes to whatever is already there"? ie. a shallow merge
let [ options ] = validateArguments(arguments, { let [ options ] = validateArguments(arguments, {
options: [ required, wrapValueAsOption("update"), { options: [ required, wrapValueAsOption("update"), {
id: [ defaultTo(item.id), isString ], id: [ defaultTo(item.id), isString ],

@ -8,7 +8,14 @@ const logStatus = require("./util/log-status");
module.exports = function ({ backend }) { module.exports = function ({ backend }) {
return function runTask(task, item) { return function runTask(task, item) {
let queue = []; let queue = [];
let api = backend.forItem({ task: task, item: item, mutationQueue: queue }); let itemIsDeleted = false;
let api = backend.forItem({
task: task,
item: item,
mutationQueue: queue,
onDeleteSelf: () => { itemIsDeleted = true; }
});
return Promise.try(() => { return Promise.try(() => {
// TODO: Standardize logging control/levels interface, also for library use // TODO: Standardize logging control/levels interface, also for library use
@ -30,7 +37,9 @@ module.exports = function ({ backend }) {
}); });
}); });
}).then(async () => { }).then(async () => {
await api.internal.markTaskCompleted(); if (!itemIsDeleted) {
await api.internal.markTaskCompleted();
}
if (!process.env.SRAP_QUIET) { if (!process.env.SRAP_QUIET) {
logStatus(task, chalk.bold.green, "completed", item.id); logStatus(task, chalk.bold.green, "completed", item.id);

Loading…
Cancel
Save