Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test alerting demo #25136

Merged
merged 18 commits into from
Nov 19, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions x-pack/plugins/task_manager/task_store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,11 @@ describe('TaskStore', () => {
maxAttempts: 2,
supportedTypes: ['report', 'dernstraight', 'yawn'],
});

const result = await store.schedule(task);

sinon.assert.calledOnce(callCluster);
sinon.assert.calledTwice(callCluster);

return { result, callCluster, arg: callCluster.args[0][1] };
return { result, callCluster, arg: callCluster.args[1][1] };
}

test('serializes the params and state', async () => {
Expand All @@ -67,7 +66,6 @@ describe('TaskStore', () => {
};
const { callCluster, arg } = await testSchedule(task);

sinon.assert.calledOnce(callCluster);
sinon.assert.calledWith(callCluster, 'index');

expect(arg).toMatchObject({
Expand Down
72 changes: 39 additions & 33 deletions x-pack/plugins/task_manager/task_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export class TaskStore {
private index: string;
private maxAttempts: number;
private supportedTypes: string[];
private wasInitialized = false;

/**
* Constructs a new TaskStore.
Expand All @@ -88,43 +89,47 @@ export class TaskStore {
* Initializes the store, ensuring the task manager index is created and up to date.
*/
public async init() {
const properties = {
type: { type: 'keyword' },
task: {
properties: {
taskType: { type: 'keyword' },
runAt: { type: 'date' },
interval: { type: 'text' },
attempts: { type: 'integer' },
status: { type: 'keyword' },
params: { type: 'text' },
state: { type: 'text' },
user: { type: 'keyword' },
scope: { type: 'keyword' },
if (!this.wasInitialized) {
njd5475 marked this conversation as resolved.
Show resolved Hide resolved
const properties = {
type: { type: 'keyword' },
task: {
properties: {
taskType: { type: 'keyword' },
runAt: { type: 'date' },
interval: { type: 'text' },
attempts: { type: 'integer' },
status: { type: 'keyword' },
params: { type: 'text' },
state: { type: 'text' },
user: { type: 'keyword' },
scope: { type: 'keyword' },
},
},
},
};

try {
return await this.callCluster('indices.putTemplate', {
name: this.index,
body: {
index_patterns: [this.index],
mappings: {
_doc: {
dynamic: 'strict',
properties,
};

try {
return await this.callCluster('indices.putTemplate', {
name: this.index,
body: {
index_patterns: [this.index],
mappings: {
_doc: {
dynamic: 'strict',
properties,
},
},
settings: {
number_of_shards: 1,
auto_expand_replicas: '0-1',
},
},
settings: {
number_of_shards: 1,
auto_expand_replicas: '0-1',
},
},
});
} catch (err) {
throw err;
});
} catch (err) {
throw err;
}
this.wasInitialized = true;
}
return;
}

/**
Expand All @@ -133,6 +138,7 @@ export class TaskStore {
* @param task - The task being scheduled.
*/
public async schedule(taskInstance: TaskInstance): Promise<ConcreteTaskInstance> {
await this.init();
if (!this.supportedTypes.includes(taskInstance.taskType)) {
throw new Error(`Unsupported task type "${taskInstance.taskType}".`);
}
Expand Down