Keep each run's log file with the run when two overlap - #131
Open
Thoroslives wants to merge 1 commit into
Open
Conversation
The current log file was one process global. A run starting while another was active returned early from log_to_file, wrote its lines into the first run's file, and on finishing recorded that file as its own and set the global to None. The first run then wrote nothing more to disk and recorded no log file at all. A Sonarr or Radarr import landing during a scheduled bulk import does exactly this, and it is the long run that loses its log. The path now lives in a thread local. A run and everything it logs share one thread, so each run keeps its own file with no change at the call sites. The two runs that continue on another thread carry the path across: a webhook retry passes it through the Timer arguments, and a chunked upload keeps it in upload_run_metadata and resumes it on each chunk, on completion and in the timeout watchdog. The history record and the viewer are unchanged. A row with no file now gets the "no associated log file" notice instead of a failed load.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The per-run log from #124 keeps the current file in one global. A run that starts while another is still going returns early from
log_to_fileand writes into the first run's file. On finishing it records that file as its own and sets the global toNone. The first run then logs nothing more and records nolog_file. A Sonarr or Radarr import landing during a scheduled bulk import does exactly this, and deleting the webhook row afterwards deletes the bulk run's file.The path is now a thread local. A run and everything it logs share one thread, so the call sites do not change. Two kinds of run continue on another thread and carry the path across. A webhook retry passes it through the
Timerarguments. A chunked ZIP upload keeps it inupload_run_metadataand resumes it on each chunk, on completion and in the timeout watchdog.The history format and the viewer do not change. A row with an empty
log_filenow gets the "no associated log file" notice instead of a failed load.Tests:
tests/test_run_log_file.pycovers the overlap, same-thread reuse and the resume across a thread.tests/test_webhook_service.pygains a test that a retry records the file the first attempt opened.