Conversation
Contributor
|
All contributors have signed the CLA ✍️ ✅ |
Author
|
I have read the CLA Document and I hereby sign the CLA |
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.
Thanks for your contribution and we appreciate it a lot. The following instructions would make your pull request more healthy and more easily get feedback. If you do not understand some items, don't worry, just make the pull request and seek help from maintainers.
Motivation
In
mineru-api(mineru/cli/fast_api.py),AsyncTaskManagermanages asynchronous parsing tasks and cleans up expired output directories viacleanup_expired_tasks(). However,cleanup_expired_tasks()only iterates over tasks tracked in the in-memoryself.tasksdictionary.When the service process restarts, crashes, or is redeployed, the in-memory
self.tasksdictionary is reset to empty. Any output directories generated underoutput_rootprior to the restart become orphaned: they are never tracked in memory again and therefore are never deleted bycleanup_expired_tasks(). Over time, these orphaned directories accumulate permanently on disk, leading to disk space leakage in production environments with routine container restarts.This PR introduces an orphan directory scanner on disk that safely identifies and removes expired output directories whose modification times exceed
task_retention_seconds, both at server startup and during the periodic background cleanup loop.Modification
cleanup_orphan_output_dirs(self) -> inttoAsyncTaskManager(mineru/cli/fast_api.py):output_root.task_id in self.tasks and self.tasks[task_id].status not in (TASK_COMPLETED, TASK_FAILED)).(now - mtime) >= self.task_retention_seconds. If expired, safely removes the directory viacleanup_file().self.cleanup_orphan_output_dirs()instart_cleanup_loop()upon service startup so leftover directories from previous runs are cleaned up immediately.self.cleanup_orphan_output_dirs()inside_cleanup_loop()alongsideself.cleanup_expired_tasks().BC-breaking (Optional)
No breaking changes. This is an internal directory lifecycle maintenance fix that respects the existing
task_retention_secondsconfiguration and maintains full backward compatibility.Use cases (Optional)
mineru-apiin containerized environments (e.g., Kubernetes pods or Docker containers) with frequent redeployments, preventing abandoned disk directories from accumulating and exhausting storage.Checklist
Before PR:
After PR: