From 7665720d77704f51953bef492b92100e2af8fba0 Mon Sep 17 00:00:00 2001 From: ansuz Date: Tue, 23 Apr 2019 13:28:05 +0200 Subject: [PATCH] integrate task execution into the server directly --- server.js | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/server.js b/server.js index daa2a0aed..b10b32da8 100644 --- a/server.js +++ b/server.js @@ -254,17 +254,28 @@ var nt = nThen(function (w) { Logger.create(config, w(function (_log) { log = config.log = _log; })); -}).nThen(function (w) { - var Tasks = require("./storage/tasks"); - //log.debug('loading task scheduler'); - Tasks.create(config, w(function (e, tasks) { - config.tasks = tasks; - })); }).nThen(function (w) { if (config.useExternalWebsocket) { return; } Storage.create(config, w(function (_store) { config.store = _store; })); +}).nThen(function (w) { + if (!config.enableTaskScheduling) { return; } + var Tasks = require("./storage/tasks"); + Tasks.create(config, w(function (e, tasks) { + if (e) { + throw e; + } + config.tasks = tasks; + 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 + })); }).nThen(function (w) { config.rpc = typeof(config.rpc) === 'undefined'? './rpc.js' : config.rpc; if (typeof(config.rpc) !== 'string') { return; }