-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
allows Alerts to recover gracefully from Executor errors #53688
Merged
Merged
Changes from 8 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
f2971df
refactored alert task runner
gmmorris e47f645
handle exceptions in alert executor
gmmorris ae37c2d
log error in alert executor
gmmorris 628b4c9
Merge branch 'master' into alerting/zombie-tasks
gmmorris d5991af
wrap alert validation in task runner to prevent failing the task
gmmorris 6ce8199
Merge branch 'master' into alerting/zombie-tasks
elasticmachine 6223180
Merge branch 'master' into alerting/zombie-tasks
gmmorris d1ef6ef
cleaned up naming
gmmorris cb652c8
Merge branch 'master' into alerting/zombie-tasks
gmmorris 0ae7220
split up alerting lib folder
gmmorris 8fdc4b0
split TaskRunner tests from Factory
gmmorris d8a07e1
removed unused imports
gmmorris 0a7dcf3
moved alerts_client_factory
gmmorris 5a2bbe1
Merge branch 'master' into alerting/zombie-tasks
gmmorris 8c34d4a
Merge branch 'master' into alerting/zombie-tasks
gmmorris 2c163ea
Merge branch 'master' into alerting/zombie-tasks
gmmorris 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 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,54 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export interface Ok<T> { | ||
tag: 'ok'; | ||
value: T; | ||
} | ||
|
||
export interface Err<E> { | ||
tag: 'err'; | ||
error: E; | ||
} | ||
export type Result<T, E> = Ok<T> | Err<E>; | ||
|
||
export function asOk<T>(value: T): Ok<T> { | ||
return { | ||
tag: 'ok', | ||
value, | ||
}; | ||
} | ||
|
||
export function asErr<T>(error: T): Err<T> { | ||
return { | ||
tag: 'err', | ||
error, | ||
}; | ||
} | ||
|
||
export function isOk<T, E>(result: Result<T, E>): result is Ok<T> { | ||
return result.tag === 'ok'; | ||
} | ||
|
||
export function isErr<T, E>(result: Result<T, E>): result is Err<E> { | ||
return !isOk(result); | ||
} | ||
|
||
export async function promiseResult<T, E>(future: Promise<T>): Promise<Result<T, E>> { | ||
try { | ||
return asOk(await future); | ||
} catch (e) { | ||
return asErr(e); | ||
} | ||
} | ||
|
||
export function map<T, E, Resolution>( | ||
result: Result<T, E>, | ||
onOk: (value: T) => Resolution, | ||
onErr: (error: E) => Resolution | ||
): Resolution { | ||
return isOk(result) ? onOk(result.value) : onErr(result.error); | ||
} |
Oops, something went wrong.
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.
map
doesn't seem like a great name for this function;processResult()
,handleResult()
, something like that?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.
It's actually a standard name for this operation in FP... it's mapping the Result type, be it an
Ok
or anErr
into a specific type.And TBH I don't feel
process
andhandle
tell me anything about what is happening here.