2016-06-02 18:26:20 +08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var assert = require('assert');
|
2019-10-04 00:24:39 +08:00
|
|
|
var JobStatus = require('../job-status');
|
2016-06-02 18:26:20 +08:00
|
|
|
var validStatusTransitions = [
|
2016-10-10 18:09:13 +08:00
|
|
|
[JobStatus.PENDING, JobStatus.RUNNING],
|
|
|
|
[JobStatus.PENDING, JobStatus.CANCELLED],
|
|
|
|
[JobStatus.PENDING, JobStatus.UNKNOWN],
|
|
|
|
[JobStatus.PENDING, JobStatus.SKIPPED],
|
|
|
|
[JobStatus.RUNNING, JobStatus.DONE],
|
|
|
|
[JobStatus.RUNNING, JobStatus.FAILED],
|
|
|
|
[JobStatus.RUNNING, JobStatus.CANCELLED],
|
|
|
|
[JobStatus.RUNNING, JobStatus.PENDING],
|
|
|
|
[JobStatus.RUNNING, JobStatus.UNKNOWN]
|
2016-06-02 18:26:20 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
function JobStateMachine () {
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = JobStateMachine;
|
|
|
|
|
|
|
|
JobStateMachine.prototype.isValidTransition = function (initialStatus, finalStatus) {
|
2019-12-24 01:19:08 +08:00
|
|
|
var transition = [initialStatus, finalStatus];
|
2016-06-02 18:26:20 +08:00
|
|
|
|
|
|
|
for (var i = 0; i < validStatusTransitions.length; i++) {
|
|
|
|
try {
|
2019-12-26 21:01:18 +08:00
|
|
|
assert.deepStrictEqual(transition, validStatusTransitions[i]);
|
2016-06-02 18:26:20 +08:00
|
|
|
return true;
|
|
|
|
} catch (e) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
JobStateMachine.prototype.isFinalStatus = function (status) {
|
2016-10-10 18:09:13 +08:00
|
|
|
return JobStatus.isFinal(status);
|
2016-06-02 18:26:20 +08:00
|
|
|
};
|