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

@@ -245,6 +245,7 @@ module.exports.create = function (config, cb) {
Workers.initialize(Env, {
blobPath: config.blobPath,
blobStagingPath: config.blobStagingPath,
taskPath: config.taskPath,
pinPath: pinPath,
filePath: config.filePath,
archivePath: config.archivePath,
@@ -257,26 +258,25 @@ module.exports.create = function (config, cb) {
}
}));
}).nThen(function (w) {
// create a task store
// create a task store (for scheduling tasks)
require("./storage/tasks").create(config, w(function (e, tasks) {
if (e) {
throw e;
}
if (e) { throw e; }
Env.tasks = tasks;
config.tasks = tasks;
if (config.disableIntegratedTasks) { return; }
config.intervals = config.intervals || {};
// XXX
config.intervals.taskExpiration = setInterval(function () {
tasks.runAll(function (err) {
if (err) {
// either TASK_CONCURRENCY or an error with tasks.list
// in either case it is already logged.
}
});
}, 1000 * 60 * 5); // run every five minutes
}));
if (config.disableIntegratedTasks) { return; }
config.intervals = config.intervals || {};
var tasks_running;
config.intervals.taskExpiration = setInterval(function () {
if (tasks_running) { return; }
tasks_running = true;
Env.runTasks(function (err) {
if (err) {
Log.error('TASK_RUNNER_ERR', err);
}
tasks_running = false;
});
}, 1000 * 60 * 5); // run every five minutes
}).nThen(function () {
RPC.create(Env, function (err, _rpc) {
if (err) { throw err; }