mirror of
https://github.com/flibusta-apps/fb2converter_server.git
synced 2025-12-06 06:55:36 +01:00
Fix bugs
This commit is contained in:
20
app/main.py
20
app/main.py
@@ -1,6 +1,6 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
|
||||||
import os
|
import os
|
||||||
|
import os.path
|
||||||
import time
|
import time
|
||||||
from typing import AsyncIterator
|
from typing import AsyncIterator
|
||||||
import uuid
|
import uuid
|
||||||
@@ -96,16 +96,12 @@ app.include_router(router)
|
|||||||
|
|
||||||
@app.on_event("startup")
|
@app.on_event("startup")
|
||||||
@repeat_every(seconds=60, raise_exceptions=True)
|
@repeat_every(seconds=60, raise_exceptions=True)
|
||||||
async def remove_temp_files():
|
def remove_temp_files():
|
||||||
def _foo():
|
current_time = time.time()
|
||||||
current_time = time.time()
|
|
||||||
|
|
||||||
for f in os.listdir("/tmp/"):
|
for f in os.listdir("/tmp/"):
|
||||||
creation_time = os.path.getctime(f)
|
target_path = f"/tmp/{f}"
|
||||||
if (current_time - creation_time) // 3600 >= 3:
|
|
||||||
os.unlink(f)
|
|
||||||
|
|
||||||
loop = asyncio.get_event_loop()
|
creation_time = os.path.getctime(target_path)
|
||||||
|
if (current_time - creation_time) // 3600 >= 3:
|
||||||
with ThreadPoolExecutor(1) as executor:
|
os.unlink(target_path)
|
||||||
await loop.run_in_executor(executor, _foo)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user