Skip to content

Commit

Permalink
assert unintialized and check for duplicates in registerTaskDefinitions
Browse files Browse the repository at this point in the history
  • Loading branch information
tsullivan committed Oct 3, 2018
1 parent 33e18f0 commit ea8e5d3
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions x-pack/plugins/task_manager/task_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,17 @@ export class TaskManager {
});
}

/**
* Method for allowing consumers to register task definitions into the system.
* @param taskDefinitions - The Kibana task definitions dictionary
*/
public registerTaskDefinitions(taskDefinitions: TaskDictionary<TaskDefinition>) {
this.assertUninitialized('register task definitions');
const duplicate = Object.keys(taskDefinitions).find(k => !!this.definitions[k]);
if (duplicate) {
throw new Error(`Task ${duplicate} is already defined!`);
}

const sanitized = sanitizeTaskDefinitions(
taskDefinitions,
this.maxWorkers,
Expand Down

0 comments on commit ea8e5d3

Please sign in to comment.