瀏覽代碼

fix(server): Script do not update config file when it runs loop process. So sometime oasx do not update this schedule

ryland 2 年之前
父節點
當前提交
ffa80687a9
共有 3 個文件被更改,包括 7 次插入 和 4 次删除
  1. 3 1
      module/server/main_manager.py
  2. 3 3
      module/server/script_router.py
  3. 1 0
      script.py

+ 3 - 1
module/server/main_manager.py

@@ -31,7 +31,7 @@ class MainManager(ConfigManager):
         self.push_data_thread = Thread(target=self.start_push_data_thread, daemon=True)
         self.push_data_thread.start()
 
-    def ensure_config_cache(self, config_name):
+    def ensure_config_cache(self, config_name: str, reload: bool = False):
         if self.config_cache is None:
             if config_name not in self._all_script_files:
                 logger.warning(f'[{config_name}] script file does not exist')
@@ -39,6 +39,8 @@ class MainManager(ConfigManager):
             self.config_cache = Config(config_name)
         elif self.config_cache.config_name != config_name:
             self.config_cache = Config(config_name)
+        if reload:
+            self.config_cache = Config(config_name)
         return self.config_cache
 
     def add_script_file(self, file_name: str):

+ 3 - 3
module/server/script_router.py

@@ -138,7 +138,7 @@ async def websocket_endpoint(websocket: WebSocket, script_name: str):
     script_process = mm.script_process[script_name]
     await script_process.connect(websocket)
     await script_process.broadcast_state({"state": script_process.state})
-    mm.ensure_config_cache(script_name)
+    mm.ensure_config_cache(script_name, reload=True)
     mm.config_cache.update_scheduler()
     await script_process.broadcast_state({"schedule": mm.config_cache.get_schedule_data()})
 
@@ -147,9 +147,9 @@ async def websocket_endpoint(websocket: WebSocket, script_name: str):
             # 初次进入,广播state schedule
             data = await websocket.receive_text()
             if data == 'get_state':
-                await script_process.broadcast_state({"state":script_process.state})
+                await script_process.broadcast_state({"state": script_process.state})
             elif data == 'get_schedule':
-                mm.ensure_config_cache(script_name)
+                mm.ensure_config_cache(script_name, reload=True)
                 mm.config_cache.update_scheduler()
                 await script_process.broadcast_state({"schedule":mm.config_cache.get_schedule_data()})
             elif data == 'start':

+ 1 - 0
script.py

@@ -459,6 +459,7 @@ class Script:
                 logger.critical('Request human takeover')
                 exit(1)
 
+            self.config.save()
             if success:
                 del_cached_property(self, 'config')
                 continue