forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
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
move to task manager module to src/server #2
Merged
chrisdavies
merged 6 commits into
chrisdavies:alerting/task-scheduler
from
tsullivan:alerting/task-scheduler-srcserver
Sep 6, 2018
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6012f31
revert x-pack change
tsullivan b2a014f
move cancellable to src/utils
tsullivan 6452315
move to src/server
tsullivan 3630e8c
use afterPluginsInit hook
tsullivan 1e60301
task_manager.ts rename
tsullivan 79a930e
add a wrapper with a setClient method
tsullivan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
export { taskManagerMixin } from './task_manager'; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import Joi from 'joi'; | ||
import { | ||
Logger, | ||
TaskDefinition, | ||
TaskDictionary, | ||
TaskManager, | ||
TaskPool, | ||
TaskStore, | ||
validateTaskDefinition, | ||
} from './task_pool'; | ||
import { SanitizedTaskDefinition } from './task_pool/task'; | ||
|
||
export async function taskManagerMixin(kbnServer: any, server: any, config: any) { | ||
const logger = new Logger((...args) => server.log(...args)); | ||
const numWorkers = config.get('taskManager.num_workers'); | ||
|
||
kbnServer.afterPluginsInit(async () => { | ||
const callCluster = server.plugins.elasticsearch.getCluster('admin').callWithInternalUser; | ||
const store = new TaskStore({ | ||
index: config.get('taskManager.index'), | ||
callCluster, | ||
maxAttempts: config.get('taskManager.max_attempts'), | ||
}); | ||
|
||
logger.debug('Initializing the task manager index'); | ||
await store.init(); | ||
|
||
const definitions = extractTaskDefinitions(numWorkers, kbnServer.uiExports.taskDefinitions); | ||
|
||
const pool = new TaskPool({ | ||
logger, | ||
callCluster, | ||
numWorkers, | ||
store, | ||
definitions, | ||
pollInterval: config.get('taskManager.poll_interval'), | ||
kbnServer, | ||
}); | ||
|
||
pool.start(); | ||
|
||
server.decorate( | ||
'server', | ||
'taskManager', | ||
new TaskManager({ | ||
store, | ||
pool, | ||
}) | ||
); | ||
}); | ||
} | ||
|
||
// TODO, move this to a file and properly test it, validate the taskDefinition via Joi or something | ||
function extractTaskDefinitions( | ||
numWorkers: number, | ||
taskDefinitions: TaskDictionary<TaskDefinition> = {} | ||
): TaskDictionary<SanitizedTaskDefinition> { | ||
return Object.keys(taskDefinitions).reduce( | ||
(acc, type) => { | ||
const rawDefinition = taskDefinitions[type]; | ||
rawDefinition.type = type; | ||
const definition = Joi.attempt(rawDefinition, validateTaskDefinition) as TaskDefinition; | ||
const workersOccupied = Math.min(numWorkers, definition.workersOccupied || 1); | ||
|
||
acc[type] = { | ||
...definition, | ||
workersOccupied, | ||
}; | ||
|
||
return acc; | ||
}, | ||
{} as TaskDictionary<SanitizedTaskDefinition> | ||
); | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the trailing comma! :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Me too, haha. I just checked out this file from master to revert it. I didn't want a change in an unrelated file to be extra noise