Skip to content

Commit

Permalink
Use task.type first to look up task runner
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Mäder <tmader@redhat.com>
  • Loading branch information
tsmaeder committed Apr 15, 2021
1 parent 8c9fb88 commit c1841b3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
18 changes: 12 additions & 6 deletions packages/task/src/node/task-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,20 @@ export class TaskRunnerRegistry {
}

/**
* Retrieves the {@link TaskRunner} registered for the specified Task type.
* @param type the task type.
* Looks for a registered {@link TaskRunner} for each of the task types in sequence and returns the first that is found
* If no task runner is registered for any of the types, the default runner is returned.
* @param types the task types.
*
* @returns the registered {@link TaskRunner} or a default runner if none is registered for the specified type.
* @returns the registered {@link TaskRunner} or a default runner if none is registered for the specified types.
*/
getRunner(type: string): TaskRunner {
const runner = this.runners.get(type);
return runner ? runner : this.defaultRunner;
getRunner(...types: string[]): TaskRunner {
for (const type of types) {
const runner = this.runners.get(type);
if (runner) {
return runner;
}
}
return this.defaultRunner;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/task/src/node/task-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class TaskServerImpl implements TaskServer, Disposable {
}

async run(taskConfiguration: TaskConfiguration, ctx?: string, option?: RunTaskOption): Promise<TaskInfo> {
const runner = this.runnerRegistry.getRunner(taskConfiguration.taskType);
const runner = this.runnerRegistry.getRunner(taskConfiguration.type, taskConfiguration.taskType);
const task = await runner.run(taskConfiguration, ctx);

if (!this.toDispose.has(task.id)) {
Expand Down

0 comments on commit c1841b3

Please sign in to comment.