Commit 53d0f1e0 authored by Tristan Cavelier's avatar Tristan Cavelier

JIO JobRecovey enabled

parent dd79ffbd
/*jslint indent: 2, maxlen: 80, nomen: true, sloppy: true, regexp: true */ /*jslint indent: 2, maxlen: 80, nomen: true, sloppy: true */
/*global EventEmitter, deepClone, inherits, secureMethods, defineConstant, /*global EventEmitter, deepClone, inherits, exports */
exports */ /*global enableRestAPI, enableRestParamChecker, enableJobMaker, enableJobRetry,
/*global addBlobStorageUtilities, addClassesToStorageUtilities, enableRestAPI, enableJobChecker, enableJobQueue, enableJobRecovery, enableJobTimeout,
enableRestParamChecker, enableCommandMaker, enableCommandExecuter, enableJobExecuter */
enableCommandTimeout, enableJobMaker, enableJobRetry, enableJobChecker,
enableJobQueue, enableJobRecoverer, enableJobExecuter, enableJobTimeout */
function JIO(storage_spec, options) { function JIO(storage_spec, options) {
JIO.super_.call(this); JIO.super_.call(this);
...@@ -24,7 +22,7 @@ function JIO(storage_spec, options) { ...@@ -24,7 +22,7 @@ function JIO(storage_spec, options) {
enableJobRetry(that, shared, options); enableJobRetry(that, shared, options);
// enableJobChecker(that, shared, options); // enableJobChecker(that, shared, options);
enableJobQueue(that, shared, options); enableJobQueue(that, shared, options);
// enableJobRecoverer(that, shared, options); enableJobRecovery(that, shared, options);
enableJobTimeout(that, shared, options); enableJobTimeout(that, shared, options);
enableJobExecuter(that, shared, options); enableJobExecuter(that, shared, options);
......
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true, unparam: true */
/*global setTimeout */
function enableJobRecovery(jio, shared, options) {
// dependencies
// - JobQueue enabled and before this
// uses
// - shared.job_queue JobWorkspace
function numberOrDefault(number, default_value) {
return (typeof number === 'number' &&
isFinite(number) ? number : default_value);
}
function recoverJob(param) {
shared.emit('job', param);
}
function jobWaiter(id, modified) {
return function () {
var job;
shared.job_queue.load();
job = shared.job_queue.get(id);
if (job.modified === modified) {
// job not modified, no one takes care of it
recoverJob(job);
}
};
}
var i, job_array, delay, deadline;
if (options.job_management !== false && options.job_recovery !== false) {
shared.job_queue.load();
job_array = shared.job_queue.asArray();
for (i = 0; i < job_array.length; i += 1) {
if (job_array[i].state === 'ready' ||
job_array[i].state === 'running') {
delay = numberOrDefault(job_array[i].timeout + 10000, 10000);
deadline = new Date(job_array[i].modified).getTime() + delay;
if (!isFinite(delay)) {
// 'modified' date is broken
recoverJob(job_array[i]);
} else if (deadline <= Date.now()) {
// deadline reached
recoverJob(job_array[i]);
} else {
// deadline not reached yet
// wait until deadline is reached then check job again
setTimeout(jobWaiter(job_array[i].id, job_array[i].modified),
deadline - delay);
}
}
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment