From 63d244818debd4106c60e0dcdce734e98cd2b4be Mon Sep 17 00:00:00 2001 From: oleg Date: Mon, 15 Jun 2015 22:16:46 +0300 Subject: [PATCH] add blocks support --- data/projects/project1/config.yaml | 7 +++++ lib/node.js | 44 ++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/data/projects/project1/config.yaml b/data/projects/project1/config.yaml index 8b81ab9..22bba02 100644 --- a/data/projects/project1/config.yaml +++ b/data/projects/project1/config.yaml @@ -21,6 +21,13 @@ trigger: - status: done project: project2 +blockedBy: + # - project2 + - !!js/regexp /project2|nci/ + +blocks: + - project2 + steps: - cmd: > echo "long multiline string" && diff --git a/lib/node.js b/lib/node.js index aafdc21..6da29ff 100644 --- a/lib/node.js +++ b/lib/node.js @@ -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;