diff options
| author | John Turner <jturner.usa@gmail.com> | 2025-09-29 02:56:10 -0400 |
|---|---|---|
| committer | John Turner <jturner.usa@gmail.com> | 2025-09-29 02:56:10 -0400 |
| commit | 1635e5adc0bed6a4a3996f4302750ea340aaf43e (patch) | |
| tree | 21dde7b0f7776fd6b68bfc3a06f748ff687a80e2 | |
| parent | 33f3cf33b52d42c4abd24e960ff7b96b1c316a11 (diff) | |
| download | pypaste-1635e5adc0bed6a4a3996f4302750ea340aaf43e.tar.gz | |
run vacuum task in the background
| -rw-r--r-- | pypaste/server/__init__.py | 20 | ||||
| -rw-r--r-- | pypaste/server/__main__.py | 2 |
2 files changed, 22 insertions, 0 deletions
diff --git a/pypaste/server/__init__.py b/pypaste/server/__init__.py index da5e538..6f79b65 100644 --- a/pypaste/server/__init__.py +++ b/pypaste/server/__init__.py @@ -262,6 +262,26 @@ class App: return web.HTTPOk(text=url) + async def background_vacuum(self) -> None: + while True: + try: + before = await self.storage.storage_use() + await self.storage.vacuum(self.config.storage_max_bytes) + after = await self.storage.storage_use() + + match [before, after]: + case [int(before), int(after)]: + log_info(f"vacuumed {before-after} bytes") + case [int(before), None]: + log_info(f"vacuumed {before} bytes") + case [None, None]: + pass + + except Exception as e: + log_error(f"failed to vacuum: {e}") + finally: + await asyncio.sleep(60 * 5) + def test_humanize_dehumanize_roundtrip() -> None: key = keygen(6) diff --git a/pypaste/server/__main__.py b/pypaste/server/__main__.py index be83ba2..d1dcdf4 100644 --- a/pypaste/server/__main__.py +++ b/pypaste/server/__main__.py @@ -155,6 +155,8 @@ async def main() -> int: log_info("starting pypaste") + asyncio.create_task(pypaste.background_vacuum()) + try: await asyncio.Event().wait() except asyncio.exceptions.CancelledError: |
