mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-23 23:48:56 +01:00
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:
parent
701d92e17b
commit
c535953915
1 changed files with 10 additions and 0 deletions
10
src/main.py
10
src/main.py
|
@ -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__()
|
||||
|
|
Loading…
Reference in a new issue