monitor.py to restart ingester periodically hopefully avoiding memory leaks.

This commit is contained in:
Никита Тырин 2024-09-12 14:30:59 +03:00
parent 83888cd2f9
commit 3acef66a89
2 changed files with 26 additions and 2 deletions

View File

@ -42,7 +42,7 @@ class Command(BaseCommand):
#fetching the file list
directory = input_with_timeout(f"[{current_time()}] Please enter the path to the directory containing the csv files [{previous_choice}]: ", 30)
directory = input_with_timeout(f"[{current_time()}] Please enter the path to the directory containing the csv files, timeout 60 seconds [{previous_choice}]: ", 60)
if not directory:
directory = previous_choice
@ -170,6 +170,6 @@ class Command(BaseCommand):
# Create a completion flag file
with open("ingester_done.flag", "w") as f:
f.write("done")
print("Ingester done")
print(f"[{current_time()}] Ingester done.")
asyncio.run(ingest_files())

24
monitor.py Normal file
View File

@ -0,0 +1,24 @@
import subprocess
import time
import os
def restart_script():
while True:
process = subprocess.Popen(["python", "manage.py", "ingester"])
time.sleep(7200)
if os.path.exists("ingester_done.flag"):
# Remove the flag file
os.remove("ingester_done.flag")
print("Ingester done, exiting monitor script.")
break
process.terminate()
process.wait()
print("Restarting ingester...")
if __name__ == "__main__":
restart_script()