-
Notifications
You must be signed in to change notification settings - Fork 2
Restart extractor on config change #655
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
base: master
Are you sure you want to change the base?
Changes from all commits
3f1ef43
b1b4b37
fdaf294
55fe623
8982e83
d331f2b
19b2c5d
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 |
|---|---|---|
|
|
@@ -36,6 +36,11 @@ enum ExtractorRunResult | |
| /// The extractor crashed. | ||
| /// </summary> | ||
| Error, | ||
| /// <summary> | ||
| /// The extractor was stopped with a clean shutdown. | ||
| /// But we need to restart it (possibly due to a revision change). | ||
| /// </summary> | ||
| RestartRequired | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
@@ -138,6 +143,7 @@ public async Task Run() | |
| } | ||
| else if (result == ExtractorRunResult.CleanShutdown) | ||
| { | ||
| _activeLogger.LogInformation("Extractor stopped cleanly with policy {Policy}", _params.RestartPolicy); | ||
| // Shut down, if the extractor is configured to only restart on error. | ||
| if (_params.RestartPolicy != ExtractorRestartPolicy.Always) | ||
| { | ||
|
|
@@ -147,6 +153,11 @@ public async Task Run() | |
| // Otherwise, immediately restart. | ||
| backoff = 0; | ||
| } | ||
| else if (result == ExtractorRunResult.RestartRequired) | ||
|
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. Not something that needs to be addressed in this PR, but: shouldn't this large if/else over an enum be a |
||
| { | ||
| _activeLogger.LogInformation("Extractor stopped cleanly with restart required, restarting with backoff"); | ||
| backoff = 1; | ||
Hmnt39 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| if (backoff == 0) | ||
| { | ||
|
|
@@ -328,6 +339,7 @@ private async Task<ExtractorRunResult> BuildAndRunExtractor(ServiceProvider prov | |
| { | ||
| using var internalTokenSource = CancellationTokenSource.CreateLinkedTokenSource(_source.Token); | ||
| TExtractor extractor; | ||
| var shouldRestart = false; | ||
|
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. This isn't used in the first |
||
| try | ||
| { | ||
| if (_params.AddMetrics) | ||
|
|
@@ -386,6 +398,7 @@ private async Task<ExtractorRunResult> BuildAndRunExtractor(ServiceProvider prov | |
| { | ||
| _activeLogger.LogInformation("Revision changed, reloading config"); | ||
| internalTokenSource.Cancel(); | ||
| shouldRestart = true; | ||
| await extractorTask.ConfigureAwait(false); | ||
| } | ||
|
|
||
|
|
@@ -394,6 +407,7 @@ private async Task<ExtractorRunResult> BuildAndRunExtractor(ServiceProvider prov | |
| { | ||
| ExceptionDispatchInfo.Capture(extractorTask.Exception).Throw(); | ||
| } | ||
|
|
||
| } | ||
| catch (OperationCanceledException) when (internalTokenSource.IsCancellationRequested) | ||
| { | ||
|
|
@@ -415,7 +429,11 @@ private async Task<ExtractorRunResult> BuildAndRunExtractor(ServiceProvider prov | |
|
|
||
| return ExtractorRunResult.Error; | ||
| } | ||
|
|
||
| if (shouldRestart) | ||
|
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. Add a blank line above to visually differentiate this from the try/catch. On a related note: this is a 100-line function that has got three quite distinct parts: the creation of the extractor, the waiting for the extractor or the "revision" change event, and the final restart check. I recommend splitting out the first two into separate functions - but that doesn't need to be done in this PR. |
||
| { | ||
| _activeLogger.LogInformation("Extractor stopped cleanly with policy {Policy}, restart is required", _params.RestartPolicy); | ||
| return ExtractorRunResult.RestartRequired; | ||
| } | ||
| return ExtractorRunResult.CleanShutdown; | ||
| } | ||
|
|
||
Toshad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
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.
Nitpick that you don't have to address, but: adding a comma at the end will prevent an unnecessary modification of this line the next time an enum member is added.