mirror of
https://github.com/onyx-dot-app/onyx.git
synced 2026-10-22 11:22:49 -05:00
22 lines
589 B
Python
22 lines
589 B
Python
import time
|
|
from collections.abc import Callable
|
|
from typing import Any
|
|
|
|
from danswer.utils.logger import setup_logger
|
|
|
|
|
|
logger = setup_logger()
|
|
|
|
|
|
def interval_run_job(job: Callable[[], Any], delay: int | float) -> None:
|
|
while True:
|
|
start = time.time()
|
|
logger.info(f"Running '{job.__name__}', current time: {time.ctime(start)}")
|
|
try:
|
|
job()
|
|
except Exception as e:
|
|
logger.exception(f"Failed to run update due to {e}")
|
|
sleep_time = delay - (time.time() - start)
|
|
if sleep_time > 0:
|
|
time.sleep(sleep_time)
|