Commit 14adef2e 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 87354a68
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true, unparam: true */ /*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) { function enableJobRetry(jio, shared, options) {
...@@ -11,6 +11,12 @@ function enableJobRetry(jio, shared, options) { ...@@ -11,6 +11,12 @@ function enableJobRetry(jio, shared, options) {
// - param.command // - param.command
// uses // 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.modified date
// - param.tried number >= 0 // - param.tried number >= 0
// - param.max_retry >= 0 or undefined // - param.max_retry >= 0 or undefined
...@@ -27,20 +33,19 @@ function enableJobRetry(jio, shared, options) { ...@@ -27,20 +33,19 @@ function enableJobRetry(jio, shared, options) {
shared.job_keys = arrayExtend(shared.job_keys || [], ["max_retry"]); shared.job_keys = arrayExtend(shared.job_keys || [], ["max_retry"]);
var writers_max_retry, readers_max_retry, max_retry;
function defaultMaxRetry(param) { function defaultMaxRetry(param) {
if ( if (methodType(param.method) === 'writers') {
indexOf(param.method, [ if (max_retry === undefined) {
'post', return writers_max_retry;
'put', }
'remove', return max_retry;
'putAttachment', }
'removeAttachment', if (max_retry === undefined) {
'repair' return readers_max_retry;
]) !== -1
) {
return 0;
} }
return 3; return max_retry;
} }
function positiveNumberOrDefault(number, default_value) { function positiveNumberOrDefault(number, default_value) {
...@@ -49,6 +54,25 @@ function enableJobRetry(jio, shared, options) { ...@@ -49,6 +54,25 @@ function enableJobRetry(jio, shared, options) {
number : default_value); 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 // listeners
shared.on('job', function (param) { shared.on('job', function (param) {
...@@ -73,8 +97,8 @@ function enableJobRetry(jio, shared, options) { ...@@ -73,8 +97,8 @@ function enableJobRetry(jio, shared, options) {
shared.on('jobRetry', function (param, args) { shared.on('jobRetry', function (param, args) {
if (param.state === 'running') { if (param.state === 'running') {
if (param.max_retry === undefined || if (param.max_retry === undefined ||
param.max_retry === 0 || param.max_retry === null ||
param.max_retry > param.tried) { param.max_retry >= param.tried) {
param.state = 'waiting'; param.state = 'waiting';
param.modified = new Date(); param.modified = new Date();
shared.emit('jobStop', param); 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