Skip to content

Commit

Permalink
Merge 9d5da55 into 8cfd94b
Browse files Browse the repository at this point in the history
  • Loading branch information
kellylu2sym authored Nov 10, 2017
2 parents 8cfd94b + 9d5da55 commit da4645d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
31 changes: 27 additions & 4 deletions lib/task-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,23 @@ function taskGraphFactory(
});
};

/*
*This function is help to get the task name for the task graph with
* without API path
*/
var getTaskName = function(taskNameInput){
// check if there is "/" in the input task name ,if yes
// it may have the api path before task name
var taskName = taskNameInput;
var slashOffset = taskNameInput.indexOf("\/");
if(slashOffset !== -1){
var nameArray = taskNameInput.split("\/");
// get the really taskName
taskName = nameArray[nameArray.length - 1];
}
return taskName;
};

/*
* Take the tasks definitions in this.definition.tasks, generate instanceIds
* to use for each task, and then create new Task objects that reference
Expand Down Expand Up @@ -208,10 +225,11 @@ function taskGraphFactory(
waitingOn: taskData.waitOn,
ignoreFailure: taskData.ignoreFailure
};

if (taskData.taskName) {
var taskNameInput = taskData.taskName;
var taskName = getTaskName(taskNameInput);
return self.constructTaskObject(
taskData.taskName,
taskName,
taskOverrides,
taskData.optionOverrides,
taskData.label
Expand All @@ -229,7 +247,7 @@ function taskGraphFactory(
return self;
});
};

TaskGraph.prototype.constructInlineTaskObject = function(_definition, taskOverrides,
optionOverrides, label) {

Expand Down Expand Up @@ -360,7 +378,12 @@ function taskGraphFactory(
assert.arrayOfObject(self.definition.tasks, 'Graph.tasks');
return Promise.map(self.definition.tasks, function(taskData) {
if (!_.has(taskData, 'taskDefinition')) {
return store.getTaskDefinition(taskData.taskName)
var taskNameInput = taskData.taskName;
var taskName = taskNameInput;
if(taskNameInput){
taskName = getTaskName(taskNameInput);
}
return store.getTaskDefinition(taskName)
.then(function(definition) {
return {
taskDefinition: definition,
Expand Down
7 changes: 7 additions & 0 deletions spec/lib/task-graph-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ describe('Task Graph', function () {
expect(graph).to.be.an.instanceof(TaskGraph);
});
});
it('should return ok if taskName with api path', function() {
definitions.graphDefinition.tasks[0].taskName = 'api/workflows/tasks/Task.test';
return TaskGraph.create('domain', { definition: definitions.graphDefinition })
.then(function(graph) {
expect(graph).to.be.an.instanceof(TaskGraph);
});
});

it('should fail on an invalid task definition', function() {
this.sandbox.stub(TaskGraph.prototype, '_validateTaskDefinition')
Expand Down

0 comments on commit da4645d

Please sign in to comment.