Commit e4519aa7 authored by Tristan Cavelier's avatar Tristan Cavelier

max_retry 0 equals infinite retry -> 0 equals 0 retry so 1 try is possible

For writer command, default max_retry is null (means infinite try possible).
For reader command, dofault max_retry is 2 (means 3 tries possible).
parent 133c11ef
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true, unparam: true */
/*global arrayExtend, setTimeout, indexOf, min, constants */
/*global arrayExtend, setTimeout, methodType, min, constants */
function enableJobRetry(jio, shared, options) {
......@@ -11,6 +11,12 @@ function enableJobRetry(jio, shared, options) {
// - param.command
// uses
// - options.default_writers_max_retry number >= 0 or null
// - options.default_readers_max_retry number >= 0 or null
// - options.default_max_retry number >= 0 or null
// - options.writers_max_retry number >= 0 or null
// - options.readers_max_retry number >= 0 or null
// - options.max_retry number >= 0 or null
// - param.modified date
// - param.tried number >= 0
// - param.max_retry >= 0 or undefined
......@@ -27,20 +33,19 @@ function enableJobRetry(jio, shared, options) {
shared.job_keys = arrayExtend(shared.job_keys || [], ["max_retry"]);
var writers_max_retry, readers_max_retry, max_retry;
function defaultMaxRetry(param) {
if (
indexOf(param.method, [
'post',
'put',
'remove',
'putAttachment',
'removeAttachment',
'repair'
]) !== -1
) {
return 0;
if (methodType(param.method) === 'writers') {
if (max_retry === undefined) {
return writers_max_retry;
}
return max_retry;
}
if (max_retry === undefined) {
return readers_max_retry;
}
return 3;
return max_retry;
}
function positiveNumberOrDefault(number, default_value) {
......@@ -49,6 +54,25 @@ function enableJobRetry(jio, shared, options) {
number : default_value);
}
function positiveNumberNullOrDefault(number, default_value) {
return ((typeof number === 'number' &&
number >= 0) || number === null ?
number : default_value);
}
max_retry = positiveNumberNullOrDefault(
options.max_retry || options.default_max_retry,
undefined
);
writers_max_retry = positiveNumberNullOrDefault(
options.writers_max_retry || options.default_writers_max_retry,
null
);
readers_max_retry = positiveNumberNullOrDefault(
options.readers_max_retry || options.default_readers_max_retry,
2
);
// listeners
shared.on('job', function (param) {
......@@ -73,8 +97,8 @@ function enableJobRetry(jio, shared, options) {
shared.on('jobRetry', function (param, args) {
if (param.state === 'running') {
if (param.max_retry === undefined ||
param.max_retry === 0 ||
param.max_retry > param.tried) {
param.max_retry === null ||
param.max_retry >= param.tried) {
param.state = 'waiting';
param.modified = new Date();
shared.emit('jobStop', param);
......
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