Skip to content

Always Log the Process Summary and Handle Stop Signals#789

Merged
ptr727 merged 1 commit into
developfrom
feature/always-log-summary-on-stop
Jul 1, 2026
Merged

Always Log the Process Summary and Handle Stop Signals#789
ptr727 merged 1 commit into
developfrom
feature/always-log-summary-on-stop

Conversation

@ptr727

@ptr727 ptr727 commented Jul 1, 2026

Copy link
Copy Markdown
Owner

What

When the Docker container runs monitor --preprocess --logwarning and is stopped
(docker stop = SIGTERM), no end-of-run summary was written: the process was
force-killed (exit 143) before logging, and part of the summary was suppressed by the
warning floor anyway. This makes every processing run always log its summary, and makes
any stop signal interrupt processing gracefully and still log the summary + exit code
before exiting.

How

  • Force the summary. ProcessDriver.ProcessFiles (Completed / Processing time /
    Total files / Error files) and DeleteEmptyFolders now log via LogOverrideContext()
    so they survive --logwarning, matching the already-forced Process.ProcessFiles
    counts and Exit Code. Covers the process verb, the monitor preprocess pass and each
    batch, and the standalone verbs (one ProcessFiles funnel).
  • Handle stop signals. Register PosixSignalRegistration for SIGINT, SIGTERM, and
    SIGQUIT, all routed to one handler that sets context.Cancel = true and cancels the
    shared token. On any signal, processing unwinds (in-flight ffmpeg/HandBrake already abort
    via the cancel token), the forced summary runs, and Main logs Exit Code and flushes.
    This replaces the Console.CancelKeyPress handler and the custom Ctrl+Q/Ctrl+Z key
    reader with a single consistent path (the custom keys are removed).

The command invocation stays synchronous. Confirmed against the System.CommandLine 2.0.9
source (InvocationPipeline.cs): the sync Invoke path constructs no
ProcessTerminationHandler and registers no signal handlers, so self-managing signals is
conflict-free (ProcessTerminationTimeout only applies to InvokeAsync).

Testing

  • Local, --logwarning: process logs the full forced summary (Completed/Total/Error/
    Modified/VerifyFailed/Deleted folders/Exit Code).
  • Local monitor, each of SIGINT/SIGTERM/SIGQUIT mid-run: logs Operation interrupted : <signal> + Exit Code : 0 and exits 0 (graceful), not 143.
  • dotnet test: 155 passed.

Notes

Docs: added a stop_grace_period / docker stop --time note to the monitor section so a
long in-flight encode can unwind before SIGKILL. A full async-invocation conversion (the
maintainer's longer-term goal) is scoped separately and intentionally not part of this fix.

Force the end-of-run summary (ProcessDriver counts and DeleteEmptyFolders) at
information level so it survives --logwarning. Handle SIGINT, SIGTERM, and SIGQUIT
so a stop (docker stop, Ctrl+C) cancels processing gracefully and logs the summary
and exit code before exit, instead of being force-killed (exit 143). Replace the
Console.CancelKeyPress and custom Ctrl+Q/Ctrl+Z key handlers with one
PosixSignalRegistration path.
Copilot AI review requested due to automatic review settings July 1, 2026 05:17

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Ensures PlexCleaner always emits an end-of-run summary (even under --logwarning) and cancels gracefully on stop signals so processing can unwind and still log the summary + exit code before exit (especially relevant for Docker/monitor scenarios).

Changes:

  • Force end-of-run summary lines to bypass the warning-only floor via LogOverrideContext().
  • Replace custom key-based cancellation with POSIX signal handling (SIGINT/SIGTERM/SIGQUIT) to drive a unified graceful-cancel path.
  • Document Docker stop grace guidance (stop_grace_period / docker stop --time) so long encodes have time to unwind before SIGKILL.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
README.md Adds release note + Docker stop grace guidance for monitor usage.
HISTORY.md Adds changelog entries for forced summaries and signal-based graceful interruption.
PlexCleaner/Program.cs Registers termination signal handlers and logs exit code using forced logging.
PlexCleaner/ProcessDriver.cs Forces task summary logs (completed/time/counts) to survive --logwarning.
PlexCleaner/Process.cs Forces deleted-folder summary log to survive --logwarning.
PlexCleaner/Monitor.cs Removes the old interrupt-message console prompt from monitor startup logging.

Comment thread PlexCleaner/Program.cs
@ptr727 ptr727 merged commit c89b851 into develop Jul 1, 2026
13 checks passed
@ptr727 ptr727 deleted the feature/always-log-summary-on-stop branch July 1, 2026 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants