mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-09-09 21:08:59 +00:00
feat(core): Dynamically loading dbgpts (#1211)
This commit is contained in:
43
dbgpt/app/initialization/scheduler.py
Normal file
43
dbgpt/app/initialization/scheduler.py
Normal file
@@ -0,0 +1,43 @@
|
||||
import logging
|
||||
import threading
|
||||
import time
|
||||
|
||||
import schedule
|
||||
|
||||
from dbgpt.component import BaseComponent, SystemApp
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class DefaultScheduler(BaseComponent):
|
||||
"""The default scheduler"""
|
||||
|
||||
name = "dbgpt_default_scheduler"
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
system_app: SystemApp,
|
||||
scheduler_delay_ms: int = 5000,
|
||||
scheduler_interval_ms: int = 1000,
|
||||
):
|
||||
super().__init__(system_app)
|
||||
self.system_app = system_app
|
||||
self._scheduler_interval_ms = scheduler_interval_ms
|
||||
self._scheduler_delay_ms = scheduler_delay_ms
|
||||
|
||||
def init_app(self, system_app: SystemApp):
|
||||
self.system_app = system_app
|
||||
|
||||
def after_start(self):
|
||||
thread = threading.Thread(target=self._scheduler)
|
||||
thread.start()
|
||||
|
||||
def _scheduler(self):
|
||||
time.sleep(self._scheduler_delay_ms / 1000)
|
||||
while True:
|
||||
try:
|
||||
schedule.run_pending()
|
||||
except Exception as e:
|
||||
logger.debug(f"Scheduler error: {e}")
|
||||
finally:
|
||||
time.sleep(self._scheduler_interval_ms / 1000)
|
Reference in New Issue
Block a user