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 signal
import sys import sys
import logging import logging
import threading
import warnings import warnings
from platform import system from platform import system
@ -73,6 +74,8 @@ def run():
logger.info("Starting Khoj...") logger.info("Starting Khoj...")
if args.no_gui: if args.no_gui:
# Setup task scheduler
poll_task_scheduler()
# Start Server # Start Server
configure_server(args, required=True) configure_server(args, required=True)
start_server(app, host=args.host, port=args.port, socket=args.socket) 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) 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): class ServerThread(QThread):
def __init__(self, app, host=None, port=None, socket=None): def __init__(self, app, host=None, port=None, socket=None):
super(ServerThread, self).__init__() super(ServerThread, self).__init__()