Commit 37298d30 authored by Tristan Cavelier's avatar Tristan Cavelier

jslint pass waitStatus.js

parent 8d6e596b
var waitStatus = function(spec, my) { /*jslint indent: 2, maxlen: 80, sloppy: true */
var that = jobStatus(spec, my); /*global jobStatus: true, jobManager: true */
spec = spec || {}; var waitStatus = function (spec, my) {
my = my || {}; var that = jobStatus(spec, my), priv = {};
// Attributes // spec = spec || {};
var priv = {}; my = my || {};
priv.job_id_array = spec.job_id_array || []; // Attributes //
priv.threshold = 0; priv.job_id_array = spec.job_id_array || [];
priv.threshold = 0;
// Methods // // Methods //
/** /**
* Returns the label of this status. * Returns the label of this status.
* @method getLabel * @method getLabel
* @return {string} The label: 'wait'. * @return {string} The label: 'wait'.
*/ */
that.getLabel = function() { that.getLabel = function () {
return 'wait'; return 'wait';
}; };
/** /**
* Refresh the job id array to wait. * Refresh the job id array to wait.
* @method refreshJobIdArray * @method refreshJobIdArray
*/ */
priv.refreshJobIdArray = function() { priv.refreshJobIdArray = function () {
var tmp_job_id_array = [], i; var tmp_job_id_array = [], i;
for (i = 0; i < priv.job_id_array.length; i+= 1) { for (i = 0; i < priv.job_id_array.length; i += 1) {
if (jobManager.jobIdExists(priv.job_id_array[i])) { if (jobManager.jobIdExists(priv.job_id_array[i])) {
tmp_job_id_array.push(priv.job_id_array[i]); tmp_job_id_array.push(priv.job_id_array[i]);
} }
} }
priv.job_id_array = tmp_job_id_array; priv.job_id_array = tmp_job_id_array;
}; };
/** /**
* The status must wait for the job end before start again. * The status must wait for the job end before start again.
* @method waitForJob * @method waitForJob
* @param {object} job The job to wait for. * @param {object} job The job to wait for.
*/ */
that.waitForJob = function(job) { that.waitForJob = function (job) {
var i; var i;
for (i = 0; i < priv.job_id_array.length; i+= 1) { for (i = 0; i < priv.job_id_array.length; i += 1) {
if (priv.job_id_array[i] === job.getId()) { if (priv.job_id_array[i] === job.getId()) {
return; return;
} }
} }
priv.job_id_array.push(job.getId()); priv.job_id_array.push(job.getId());
}; };
/** /**
* The status stops to wait for this job. * The status stops to wait for this job.
* @method dontWaitForJob * @method dontWaitForJob
* @param {object} job The job to stop waiting for. * @param {object} job The job to stop waiting for.
*/ */
that.dontWaitForJob = function(job) { that.dontWaitForJob = function (job) {
var i, tmp_job_id_array = []; var i, tmp_job_id_array = [];
for (i = 0; i < priv.job_id_array.length; i+= 1) { for (i = 0; i < priv.job_id_array.length; i += 1) {
if (priv.job_id_array[i] !== job.getId()){ if (priv.job_id_array[i] !== job.getId()) {
tmp_job_id_array.push(priv.job_id_array[i]); tmp_job_id_array.push(priv.job_id_array[i]);
} }
} }
priv.job_id_array = tmp_job_id_array; priv.job_id_array = tmp_job_id_array;
}; };
/** /**
* The status must wait for some milliseconds. * The status must wait for some milliseconds.
* @method waitForTime * @method waitForTime
* @param {number} ms The number of milliseconds * @param {number} ms The number of milliseconds
*/ */
that.waitForTime = function(ms) { that.waitForTime = function (ms) {
priv.threshold = Date.now() + ms; priv.threshold = Date.now() + ms;
}; };
/** /**
* The status stops to wait for some time. * The status stops to wait for some time.
* @method stopWaitForTime * @method stopWaitForTime
*/ */
that.stopWaitForTime = function() { that.stopWaitForTime = function () {
priv.threshold = 0; priv.threshold = 0;
}; };
that.canStart = function() { that.canStart = function () {
priv.refreshJobIdArray(); priv.refreshJobIdArray();
return (priv.job_id_array.length === 0 && Date.now() >= priv.threshold); return (priv.job_id_array.length === 0 && Date.now() >= priv.threshold);
}; };
that.canRestart = function() { that.canRestart = function () {
return that.canStart(); return that.canStart();
}; };
that.serialized = function() { that.serialized = function () {
return {label:that.getLabel(), return {
waitfortime:priv.threshold, "label": that.getLabel(),
waitforjob:priv.job_id_array}; "waitfortime": priv.threshold,
"waitforjob": priv.job_id_array
}; };
};
/** /**
* Checks if this status is waitStatus * Checks if this status is waitStatus
* @method isWaitStatus * @method isWaitStatus
* @return {boolean} true * @return {boolean} true
*/ */
that.isWaitStatus = function () { that.isWaitStatus = function () {
return true; return true;
}; };
return that; return that;
}; };
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