Update index automatically in non GUI mode too

- Poll scheduler every minute using threading.Timer
  - Use 60 seconds polling interval to avoid fork bombing
- Schedule next via the same poll scheduler
- Allow clean program interrupt by running scheduler in daemon mode
This commit is contained in:
Debanjum Singh Solanky 2023-01-01 20:48:13 -03:00
parent 701d92e17b
commit c535953915

View file

@ -3,6 +3,7 @@ import os
import signal
import sys
import logging
import threading
import warnings
from platform import system
@ -73,6 +74,8 @@ def run():
logger.info("Starting Khoj...")
if args.no_gui:
# Setup task scheduler
poll_task_scheduler()
# Start Server
configure_server(args, required=True)
start_server(app, host=args.host, port=args.port, socket=args.socket)
@ -143,6 +146,13 @@ def start_server(app, host=None, port=None, socket=None):
uvicorn.run(app, host=host, port=port)
def poll_task_scheduler():
timer_thread = threading.Timer(60.0, poll_task_scheduler)
timer_thread.daemon = True
timer_thread.start()
schedule.run_pending()
class ServerThread(QThread):
def __init__(self, app, host=None, port=None, socket=None):
super(ServerThread, self).__init__()