add blocks support

This commit is contained in:
oleg 2015-06-15 22:16:46 +03:00
parent 85844bcb40
commit 63d244818d
2 changed files with 51 additions and 0 deletions

View File

@ -21,6 +21,13 @@ trigger:
- status: done
project: project2
blockedBy:
# - project2
- !!js/regexp /project2|nci/
blocks:
- project2
steps:
- cmd: >
echo "long multiline string" &&

View File

@ -12,6 +12,19 @@ function Node(params) {
exports.Node = Node;
Node.prototype._getBlockerExecutor = function(getBlockers, getTarget) {
return _(this.executors).find(function(executor) {
var target = getTarget(executor);
return _(getBlockers(executor)).find(function(blocker) {
if (_(blocker).isRegExp()) {
return blocker.test(target);
} else {
return blocker === target;
}
});
})
};
Node.prototype.getExecutorWaitReason = function(project) {
var waitReason;
@ -19,6 +32,37 @@ Node.prototype.getExecutorWaitReason = function(project) {
waitReason = 'All executors are busy';
} else if (project.name in this.executors) {
waitReason = 'Project already running on node';
} else {
var blockerExecutor;
if (project.blockedBy) {
blockerExecutor = this._getBlockerExecutor(
function(executor) {
return project.blockedBy;
},
function(executor) {
return executor.project.name;
}
);
}
if (!blockerExecutor) {
blockerExecutor = this._getBlockerExecutor(
function(executor) {
return executor.project.blocks;
},
function(executor) {
return project.name;
}
);
}
if (blockerExecutor) {
waitReason = (
'Blocked by currently running "' +
blockerExecutor.project.name + '"'
);
}
}
return waitReason;