-
Notifications
You must be signed in to change notification settings - Fork 868
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
chore: Add cancellation support for PdfBuilder operation #10460
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #10460 +/- ##
==========================================
+ Coverage 74.31% 79.32% +5.00%
==========================================
Files 536 548 +12
Lines 23189 23655 +466
Branches 4056 4064 +8
==========================================
+ Hits 17234 18764 +1530
+ Misses 4853 3720 -1133
- Partials 1102 1171 +69 ☔ View full report in Codecov by Sentry. |
src/Docfx.App/PdfBuilder.cs
Outdated
|
||
task.Value = task.MaxValue; | ||
task.StopTask(); | ||
}); | ||
}); | ||
|
||
// Wait pdfBuildTask completed or cancelled. | ||
await Task.WhenAny(pdfBuildTask, Task.Delay(Timeout.Infinite, cts.Token)); |
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.
Is there a reason we are not relying on the cancellation token passed to pdfBuildTask
to gracefully cancel the PDF build job? This extra manual shutdown code looks suspicious to me.
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 required because AnsiConsole.Progress().StartAsync
and Playwright APIs doesn't support CancellationToken
parameter.
So when operation is cancelled via CancellationToken.
It takes some seconds(about 5-10 seconds) until operations are cancelled.
So I need to use Task.WhenAny
for stopping operations immediately.
And additional dipose/await code are required.
Because It can't output logs until AnsiConsole.Progress().StartAsync
is completed
(Otherwise console log is outputted to wrong places)
src/Docfx.App/PdfBuilder.cs
Outdated
@@ -641,4 +681,16 @@ private static StringComparison GetStringComparison() | |||
? StringComparison.OrdinalIgnoreCase | |||
: StringComparison.Ordinal; | |||
} | |||
|
|||
private static CancellationTokenRegistration SubscribeCancelKeyPressEvent(CancellationTokenSource cts) |
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.
This seems to apply to all build jobs, do we want to also enable it on the build command say in the future?
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'm expecting same cancellation token should be passed to Build command also in future.
9f88341
to
43bec14
Compare
What's changed on latest commit. 1.
See details: 2. 3. DefaultCommand.cs TODO
|
43bec14
to
253d001
Compare
This PR intended to fix issue #9870.
Currently when running
docfx pdf
command.Ctrl+C
command interruption is not accepted.So I've added codes to manually cancel running operations.
Note
Playwright don't supports cancellationToken parameters.
So it need manually cancel operation by dispose playwright context.
Specre.Console
don't support native cancellation support .So PdfCommand/DefaultCommand is not modified. (It need to migrate to
AsyncCommand
in future)https://github.com/spectreconsole/spectre.console/issues/701
What's changed in this PR
Console.CancelKeyPress
event handlers to cancel running operationscancellationToken
parameter to following methods3.1. WebApplication.Start
3.2.
ParallelOptions
parameter ofParallel.Foreach
cancellationToken.ThrowIfCancellationRequested()
inside loop.outputPath
parameter topdfOutputPath
.