Skip to content

Keep each run's log file with the run when two overlap - #131

Open
Thoroslives wants to merge 1 commit into
mscodemonkey:mainfrom
Thoroslives:upstream/per-run-log-file
Open

Keep each run's log file with the run when two overlap#131
Thoroslives wants to merge 1 commit into
mscodemonkey:mainfrom
Thoroslives:upstream/per-run-log-file

Conversation

@Thoroslives

Copy link
Copy Markdown
Contributor

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_file and writes into the first run's file. On finishing it records that file as its own and sets the global to None. The first run then logs nothing more and records no log_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 Timer arguments. A chunked ZIP upload keeps it in upload_run_metadata and 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_file now gets the "no associated log file" notice instead of a failed load.

Tests: tests/test_run_log_file.py covers the overlap, same-thread reuse and the resume across a thread. tests/test_webhook_service.py gains a test that a retry records the file the first attempt opened.

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.
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.

1 participant