-
Notifications
You must be signed in to change notification settings - Fork 8.3k
/
Copy pathindex.ts
68 lines (63 loc) · 1.77 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { Observable } from 'rxjs';
import { CoreSetup, Logger } from 'kibana/server';
import { PLUGIN_ID, VIS_TELEMETRY_TASK } from '../../../constants';
import { visualizationsTaskRunner } from './visualizations/task_runner';
import {
TaskInstance,
TaskManagerStartContract,
TaskManagerSetupContract,
} from '../../../../task_manager/server';
export function registerTasks({
taskManager,
logger,
elasticsearch,
config,
}: {
taskManager?: TaskManagerSetupContract;
logger: Logger;
elasticsearch: CoreSetup['elasticsearch'];
config: Observable<{ kibana: { index: string } }>;
}) {
if (!taskManager) {
logger.debug('Task manager is not available');
return;
}
taskManager.registerTaskDefinitions({
[VIS_TELEMETRY_TASK]: {
title: 'X-Pack telemetry calculator for Visualizations',
type: VIS_TELEMETRY_TASK,
createTaskRunner({ taskInstance }: { taskInstance: TaskInstance }) {
return {
run: visualizationsTaskRunner(taskInstance, config, elasticsearch),
};
},
},
});
}
export async function scheduleTasks({
taskManager,
logger,
}: {
taskManager?: TaskManagerStartContract;
logger: Logger;
}) {
if (!taskManager) {
logger.debug('Task manager is not available');
return;
}
try {
await taskManager.ensureScheduled({
id: `${PLUGIN_ID}-${VIS_TELEMETRY_TASK}`,
taskType: VIS_TELEMETRY_TASK,
state: { stats: {}, runs: 0 },
params: {},
});
} catch (e) {
logger.debug(`Error scheduling task, received ${e.message}`);
}
}