run expiration tasks in a worker instead of the main process

This commit is contained in:
ansuz
2020-03-27 14:38:58 -04:00
parent b0179eaad9
commit d8a88cb4ca
3 changed files with 43 additions and 18 deletions

View File

@@ -11,6 +11,7 @@ const Pins = require("../pins");
const Core = require("../commands/core");
const Saferphore = require("saferphore");
const Logger = require("../log");
const Tasks = require("../storage/tasks");
const Env = {
Log: {},
@@ -31,6 +32,7 @@ var ready = false;
var store;
var pinStore;
var blobStore;
var tasks;
const init = function (config, _cb) {
const cb = Util.once(Util.mkAsync(_cb));
if (!config) {
@@ -66,6 +68,18 @@ const init = function (config, _cb) {
}
blobStore = blob;
}));
}).nThen(function (w) {
Tasks.create({
log: Env.Log,
taskPath: config.taskPath,
store: store,
}, w(function (err, tasks) {
if (err) {
w.abort();
return void cb(err);
}
Env.tasks = tasks;
}));
}).nThen(function () {
cb();
});
@@ -393,6 +407,10 @@ const removeOwnedBlob = function (data, cb) {
});
};
const runTasks = function (data, cb) {
Env.tasks.runAll(cb);
};
const COMMANDS = {
COMPUTE_INDEX: computeIndex,
COMPUTE_METADATA: computeMetadata,
@@ -404,6 +422,7 @@ const COMMANDS = {
GET_MULTIPLE_FILE_SIZE: getMultipleFileSize,
GET_HASH_OFFSET: getHashOffset,
REMOVE_OWNED_BLOB: removeOwnedBlob,
RUN_TASKS: runTasks,
};
process.on('message', function (data) {
@@ -439,7 +458,7 @@ process.on('message', function (data) {
});
process.on('uncaughtException', function (err) {
console.error('[%s] UNCAUGHT EXCEPTION IN DB WORKER');
console.error('[%s] UNCAUGHT EXCEPTION IN DB WORKER', new Date());
console.error(err);
console.error("TERMINATING");
process.exit(1);

View File

@@ -290,6 +290,12 @@ Workers.initializeIndexWorkers = function (Env, config, _cb) {
}, cb);
};
Env.runTasks = function (cb) {
sendCommand({
command: 'RUN_TASKS',
}, cb);
};
//console.log("index workers ready");
cb(void 0);
});