kibana/x-pack/plugins/oss_telemetry/server/lib/tasks/index.ts
Tim Sullivan df19d7e80d
Telemetry for Visualizations by type (#28793) (#29625)
* task runner and usage collector for visualizations by type

* type is always just "visualization"

* drop the I- prefix for interfaces

* bug fixes

* ts fix

* comment perfection

* just usage.

* const for task numworkers

* use mapValues

* get next midnight module

* move to oss_telemtry

* test fix

* errMessage.includes(NotInitialized)
2019-01-31 10:53:20 -07:00

39 lines
1.3 KiB
TypeScript

/*
* 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 { HapiServer } from '../../../';
import { PLUGIN_ID, VIS_TELEMETRY_TASK, VIS_TELEMETRY_TASK_NUM_WORKERS } from '../../../constants';
import { visualizationsTaskRunner } from './visualizations/task_runner';
export function registerTasks(server: HapiServer) {
const { taskManager } = server;
taskManager.registerTaskDefinitions({
[VIS_TELEMETRY_TASK]: {
title: 'X-Pack telemetry calculator for Visualizations',
type: VIS_TELEMETRY_TASK,
numWorkers: VIS_TELEMETRY_TASK_NUM_WORKERS, // by default it's 100% their workers
createTaskRunner({ taskInstance, kbnServer }: { kbnServer: any; taskInstance: any }) {
return {
run: visualizationsTaskRunner(taskInstance, kbnServer),
};
},
},
});
}
export function scheduleTasks(server: HapiServer) {
const { taskManager } = server;
const { kbnServer } = server.plugins.xpack_main.status.plugin;
kbnServer.afterPluginsInit(() => {
taskManager.schedule({
id: `${PLUGIN_ID}-${VIS_TELEMETRY_TASK}`,
taskType: VIS_TELEMETRY_TASK,
state: { stats: {}, runs: 0 },
});
});
}