WIP
parent
1acc039897
commit
128b70fdae
@ -0,0 +1,31 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const Promise = require("bluebird");
|
||||||
|
const yargs = require("yargs");
|
||||||
|
const path = require("path");
|
||||||
|
|
||||||
|
const createKernel = require("../src/kernel");
|
||||||
|
const chalk = require("chalk");
|
||||||
|
|
||||||
|
let argv = yargs.argv;
|
||||||
|
let [ configurationPath, task, item ] = argv._;
|
||||||
|
let absoluteConfigurationPath = path.join(process.cwd(), configurationPath);
|
||||||
|
|
||||||
|
let configuration = require(absoluteConfigurationPath);
|
||||||
|
|
||||||
|
return Promise.try(() => {
|
||||||
|
return createKernel(configuration);
|
||||||
|
}).then((kernel) => {
|
||||||
|
return Promise.try(() => {
|
||||||
|
return kernel.execute({
|
||||||
|
task: task,
|
||||||
|
itemID: item
|
||||||
|
});
|
||||||
|
}).then(() => {
|
||||||
|
console.log(chalk.green.bold("Done!"));
|
||||||
|
}).finally(() => {
|
||||||
|
kernel.shutdown();
|
||||||
|
});
|
||||||
|
});
|
@ -0,0 +1,17 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
module.exports.up = function(knex, Promise) {
|
||||||
|
return knex.schema
|
||||||
|
.alterTable("srap_aliases", (table) => {
|
||||||
|
table.timestamp("created_at").notNullable().defaultTo(knex.fn.now());
|
||||||
|
table.timestamp("updated_at").notNullable().defaultTo(knex.fn.now());
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.down = function(knex, Promise) {
|
||||||
|
return knex.schema
|
||||||
|
.alterTable("srap_aliases", (table) => {
|
||||||
|
table.dropColumn("created_at");
|
||||||
|
table.dropColumn("updated_at");
|
||||||
|
});
|
||||||
|
};
|
@ -0,0 +1,36 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
const Promise = require("bluebird");
|
||||||
|
const consumable = require("@joepie91/consumable");
|
||||||
|
const syncpipe = require("syncpipe");
|
||||||
|
|
||||||
|
const createMutationAPIWrapper = require("./mutation-api/wrapper");
|
||||||
|
|
||||||
|
module.exports = function (state) {
|
||||||
|
const createDatabaseMutationAPI = require("./mutation-api/database")(state);
|
||||||
|
|
||||||
|
return function createDatabaseQueue(context) {
|
||||||
|
let databaseMutationAPI = createDatabaseMutationAPI(context);
|
||||||
|
let mutationAPI = createMutationAPIWrapper(context, databaseMutationAPI);
|
||||||
|
|
||||||
|
let queue = consumable([]);
|
||||||
|
|
||||||
|
return {
|
||||||
|
api: syncpipe(Object.keys(mutationAPI), [
|
||||||
|
(_) => _.map((method) => [ method, function() { queue.peek().push([ method, arguments ]); } ]),
|
||||||
|
(_) => Object.fromEntries(_)
|
||||||
|
]),
|
||||||
|
execute: function () {
|
||||||
|
if (!queue.peek().some((method) => method[0] === "updateMetadata")) {
|
||||||
|
// Doing an updateMetadata call is necessary to mark a task 'completed', so we inject a dummy call that doesn't actually change the metadata itself
|
||||||
|
// FIXME: Split apart 'markTaskCompleted' and 'updateMetadata' queries so that this hack is no longer necessary
|
||||||
|
queue.peek().push([ "updateMetadata", [ (data) => data ]]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.each(queue.consume(), ([ method, args ]) => {
|
||||||
|
return mutationAPI[method](... args);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
Loading…
Reference in New Issue