Skip to content

Commit

Permalink
refactor(task-manager): renamed scheduleIfNotExists api to clarify wh…
Browse files Browse the repository at this point in the history
…at it does
  • Loading branch information
gmmorris committed Nov 11, 2019
1 parent 090e094 commit 1d7e751
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/task_manager/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ describe('Task Manager Plugin', () => {
expect(setupResult).toMatchInlineSnapshot(`
Object {
"addMiddleware": [Function],
"ensureScheduling": [Function],
"fetch": [Function],
"registerTaskDefinitions": [Function],
"remove": [Function],
"schedule": [Function],
"scheduleIfNotExists": [Function],
}
`);
});
Expand Down
4 changes: 2 additions & 2 deletions x-pack/legacy/plugins/task_manager/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface PluginSetupContract {
fetch: TaskManager['fetch'];
remove: TaskManager['remove'];
schedule: TaskManager['schedule'];
scheduleIfNotExists: TaskManager['scheduleIfNotExists'];
ensureScheduling: TaskManager['ensureScheduling'];
addMiddleware: TaskManager['addMiddleware'];
registerTaskDefinitions: TaskManager['registerTaskDefinitions'];
}
Expand Down Expand Up @@ -60,7 +60,7 @@ export class Plugin {
fetch: (...args) => taskManager.fetch(...args),
remove: (...args) => taskManager.remove(...args),
schedule: (...args) => taskManager.schedule(...args),
scheduleIfNotExists: (...args) => taskManager.scheduleIfNotExists(...args),
ensureScheduling: (...args) => taskManager.ensureScheduling(...args),
addMiddleware: (...args) => taskManager.addMiddleware(...args),
registerTaskDefinitions: (...args) => taskManager.registerTaskDefinitions(...args),
};
Expand Down
4 changes: 2 additions & 2 deletions x-pack/legacy/plugins/task_manager/task_manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ describe('TaskManager', () => {

client.start();

const result = await client.scheduleIfNotExists({
const result = await client.ensureScheduling({
id: 'my-foo-id',
taskType: 'foo',
params: {},
Expand All @@ -162,7 +162,7 @@ describe('TaskManager', () => {
client.start();

return expect(
client.scheduleIfNotExists({
client.ensureScheduling({
id: 'my-foo-id',
taskType: 'foo',
params: {},
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/task_manager/task_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export class TaskManager {
* @param task - The task being scheduled.
* @returns {Promise<ConcreteTaskInstance>}
*/
public async scheduleIfNotExists(
public async ensureScheduling(
taskInstance: ExistingTaskInstance,
options?: any
): Promise<ExistingTaskInstance> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,23 @@ export function initRoutes(server) {
state: Joi.object().optional(),
id: Joi.string().optional()
}),
scheduleIfNotExists: Joi.boolean()
ensureScheduling: Joi.boolean()
.default(false)
.optional(),
}),
},
},
async handler(request) {
try {
const { scheduleIfNotExists = false, task: taskFields } = request.payload;
const { ensureScheduling = false, task: taskFields } = request.payload;
const task = {
...taskFields,
scope: [scope],
};

const taskResult = await (
scheduleIfNotExists
? taskManager.scheduleIfNotExists(task, { request })
ensureScheduling
? taskManager.ensureScheduling(task, { request })
: taskManager.schedule(task, { request })
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default function ({ getService }) {
function scheduleTaskIfNotExists(task) {
return supertest.post('/api/sample_tasks')
.set('kbn-xsrf', 'xxx')
.send({ task, scheduleIfNotExists: true })
.send({ task, ensureScheduling: true })
.expect(200)
.then((response) => response.body);
}
Expand Down

0 comments on commit 1d7e751

Please sign in to comment.