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

[Task manager] Adds ensureScheduled api to allow safer rescheduling of existing tasks #50232

Merged
merged 15 commits into from
Nov 14, 2019

Conversation

gmmorris
Copy link
Contributor

@gmmorris gmmorris commented Nov 11, 2019

Summary

Adds an ensureScheduled api to Task Manager which allow safer rescheduling of existing tasks by handling the case where a Task with a known ID is scheduled and clashes with an existing schedule of that same task.

fixes #41827
fixed #32050

Checklist

Use strikethroughs to remove checklist items you don't feel are applicable to this PR.

For maintainers

@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-stack-services (Team:Stack Services)

@elasticmachine
Copy link
Contributor

💔 Build Failed

@mikecote mikecote added this to In progress in Make it Action Nov 12, 2019
@gmmorris gmmorris requested a review from a team November 12, 2019 16:24
@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@gmmorris
Copy link
Contributor Author

@elasticmachine merge upstream

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@mikecote
Copy link
Contributor

I don't see any issues calling it ensureScheduling unless others have a better suggestion (ensureScheduled?).

The interface ExistingTaskInstance is a bit strange as this API also takes non existing task instances but I get it needs to have an id. Another way could be TaskInstanceWithId.

@gmmorris
Copy link
Contributor Author

The interface ExistingTaskInstance is a bit strange as this API also takes non existing task instances but I get it needs to have an id. Another way could be TaskInstanceWithId.

Yeah, I was really unsure with that naming :)
TaskInstanceWithId could work, still feels weird 😆 ... but I guess ExistingTaskInstance is actually wrong, so I agree it should change... I'll think about it a bit more.

Copy link
Contributor

@bmcconaghy bmcconaghy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM. Thanks for tackling this.

Copy link
Member

@pmuellr pmuellr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but made a comment about changing a comment :-)

* The id of the Elastic document that stores this instance's data. This can
* be passed by the caller when scheduling the task.
*/
id: string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow, TIL. You can subclass an interface, changing a super-interface's property from optional to not optional. Neat-O!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's changed now, as I'm using a new Utility type marking id as Required ;)
But the name is now TaskInstanceWithId.

public async ensureScheduling(
taskInstance: ExistingTaskInstance,
options?: any
): Promise<ExistingTaskInstance> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I guess sometimes this will return a ConcreteTaskInstance (if not already scheduled), but otherwise the taskInstance sent in. Seems like it would be "nice" if it did always return a ConcreteTaskInstance, but guessing you will have to do another read to get that, and hardly seems worth it, since the caller may not need it. Seems like this should be fine as a first attempt, maybe we'd need to re-look at a way to get the ConcreteTaskInstance back later, if we find we need it for some reason.

In any case, the JSDoc comment above this should be changed to say it's returning an ExistingTaskInstance instead of ConcreteTaskInstance.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I did think about that, though, the type it returns will always be TaskInstanceWithId, never an explicit ConcreteTaskInstance, as TaskInstanceWithId is essentially a subtype of ConcreteTaskInstance, but you're right that otherwise we'd have to make an additional read and it didn't seem worth it.
Feels reasonable to leave it such due to the ensure nature, no?

I'll change the JSDoc, thanks for catching 👍

@pmuellr
Copy link
Member

pmuellr commented Nov 14, 2019

Same feels on the new names as everyone, I guess. ensureScheduled sounds better to me than ensureScheduling. TaskInstanceWithId sounds better than ExistingTaskInstance.

@gmmorris
Copy link
Contributor Author

Same feels on the new names as everyone, I guess. ensureScheduled sounds better to me than ensureScheduling.

Weird, to me ensureScheduled feels grammatically wrong... while ensureScheduling feels right? 🤷‍♂ Might be a US<->UK thing... anyway, happy to go with the majority on this one. :)

TaskInstanceWithId sounds better than ExistingTaskInstance.

Already changed :)

@@ -10,6 +10,8 @@ import Joi from 'joi';
* Type definitions and validations for tasks.
*/

type Require<T extends object, P extends keyof T = keyof T> = Omit<T, P> & Required<Pick<T, P>>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this new Require type could use a short comment - not immediately clear what it's doing :-)

@@ -82,7 +82,7 @@ function scheduleTasks(server: Server) {
// function block.
(async () => {
try {
await taskManager.schedule({
await taskManager.ensureScheduled({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@wylieconlon wylieconlon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lens part LGTM

@gmmorris
Copy link
Contributor Author

@elasticmachine merge upstream

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@gmmorris gmmorris merged commit d777128 into elastic:master Nov 14, 2019
gmmorris added a commit to gmmorris/kibana that referenced this pull request Nov 14, 2019
…of existing tasks (elastic#50232)

Adds an ensureScheduling api to Task Manager which allow safer rescheduling of existing tasks by handling the case where a Task with a known ID is scheduled and clashes with an existing schedule of that same task.
@gmmorris gmmorris changed the title [Task manager] Adds ensureScheduling api to allow safer rescheduling of existing tasks [Task manager] Adds ensureScheduled api to allow safer rescheduling of existing tasks Nov 14, 2019
gmmorris added a commit that referenced this pull request Nov 14, 2019
…of existing tasks (#50232) (#50705)

Adds an ensureSchedule api to Task Manager which allow safer rescheduling of existing tasks by handling the case where a Task with a known ID is scheduled and clashes with an existing schedule of that same task.
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

jloleysens added a commit to jloleysens/kibana that referenced this pull request Nov 15, 2019
…ger-ace-theme

* 'master' of github.com:elastic/kibana: (54 commits)
  [ML] Fixes word wrap in Overview page sidebar on IE (elastic#50668)
  Upgrade to TypeScript 3.7.2 (elastic#47188)
  fix: hide 'edit' button for mobile for dashboards (elastic#50639)
  fixes conditional links tests (elastic#50642)
  [SIEM] Fix IE11 timeline drag and drop issue (elastic#50528)
  [SIEM] Add SavedQuery in Timeline (elastic#49813)
  chore(NA): remove code plugin from codeowners (elastic#50451)
  [DOCS] Adds documentation on telemetry settings (elastic#50739)
  [Logs UI] Add IE11-specific CSS fixes for anomalies table (elastic#49980)
  [DOCS][SIEM]: Change Kibana advanced settings to match UI (elastic#50679)
  Change URLs for support menu (elastic#50700)
  [Reporting] Remove any types and references to Hapi (elastic#49250)
  [DOCS] Adds note about backups to Upgrade doc (elastic#50525)
  [Logs UI] Improve infra plugin compatibility with TS 3.7 (elastic#50491)
  [Task manager] Adds ensureScheduling api to allow safer rescheduling of existing tasks (elastic#50232)
  [DOCS] Adds link to content security policy doc (elastic#50698)
  Remove duplicate but in error message (elastic#50530)
  [ML] DF Analytics: Ensure creation flyout can be opened when no jobs exist (elastic#50417)
  Add filebeat notice (elastic#49065)
  [Monitoring] De-duplicate pipeline ids based on the ephemeral_id changing (elastic#49978)
  ...

# Conflicts:
#	x-pack/legacy/plugins/grokdebugger/public/components/grok_debugger/brace_imports.ts
@mikecote mikecote removed this from In progress in Make it Action Nov 18, 2019
@gmmorris gmmorris deleted the task-manager/scheduleIfNotExists branch November 21, 2019 13:46
gmmorris added a commit to gmmorris/kibana that referenced this pull request Nov 27, 2019
…of existing tasks (elastic#50232)

Adds an ensureScheduling api to Task Manager which allow safer rescheduling of existing tasks by handling the case where a Task with a known ID is scheduled and clashes with an existing schedule of that same task.
gmmorris added a commit to gmmorris/kibana that referenced this pull request Nov 27, 2019
…of existing tasks (elastic#50232)

Adds an ensureScheduling api to Task Manager which allow safer rescheduling of existing tasks by handling the case where a Task with a known ID is scheduled and clashes with an existing schedule of that same task.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants