-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Changes from 10 commits
090e094
1d7e751
aacff4d
18542d9
d90a483
0e40e28
4704660
adbc0bc
dc84500
cdf9ec5
a7d12c5
7198e4c
55499bc
97ff0aa
9d77ebc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ import { | |
TaskDefinition, | ||
TaskDictionary, | ||
ConcreteTaskInstance, | ||
ExistingTaskInstance, | ||
RunContext, | ||
TaskInstance, | ||
} from './task'; | ||
|
@@ -29,6 +30,8 @@ import { | |
} from './task_store'; | ||
import { identifyEsError } from './lib/identify_es_error'; | ||
|
||
const VERSION_CONFLICT_STATUS = 409; | ||
|
||
export interface TaskManagerOpts { | ||
logger: Logger; | ||
config: any; | ||
|
@@ -219,6 +222,26 @@ export class TaskManager { | |
return result; | ||
} | ||
|
||
/** | ||
* Schedules a task with an Id | ||
* | ||
* @param task - The task being scheduled. | ||
* @returns {Promise<ConcreteTaskInstance>} | ||
*/ | ||
public async ensureScheduling( | ||
taskInstance: ExistingTaskInstance, | ||
options?: any | ||
): Promise<ExistingTaskInstance> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I guess sometimes this will return a In any case, the JSDoc comment above this should be changed to say it's returning an There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 I'll change the JSDoc, thanks for catching 👍 |
||
try { | ||
return await this.schedule(taskInstance, options); | ||
} catch (err) { | ||
if (err.statusCode === VERSION_CONFLICT_STATUS) { | ||
return taskInstance; | ||
} | ||
throw err; | ||
} | ||
} | ||
|
||
/** | ||
* Fetches a paginatable list of scheduled tasks. | ||
* | ||
|
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.
wow, TIL. You can subclass an interface, changing a super-interface's property from optional to not optional. Neat-O!
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.
That's changed now, as I'm using a new Utility type marking
id
as Required ;)But the name is now
TaskInstanceWithId
.