Преглед на файлове

feat(tasks): #594 Delay tasks in pending during game server maintenance

ryland преди 1 година
родител
ревизия
a4b6e6101a
променени са 2 файла, в които са добавени 21 реда и са изтрити 7 реда
  1. 20 6
      tasks/Restart/script_task.py
  2. 1 1
      tasks/SoulsTidy/script_task.py

+ 20 - 6
tasks/Restart/script_task.py

@@ -1,7 +1,7 @@
 # This Python file uses the following encoding: utf-8
 # @author runhey
 # github https://github.com/runhey
-
+from datetime import datetime
 
 from tasks.Restart.config_scheduler import Scheduler
 from tasks.Restart.login import LoginHandler
@@ -12,8 +12,6 @@ from module.logger import logger
 from module.exception import TaskEnd, RequestHumanTakeover
 
 
-
-
 class ScriptTask(LoginHandler):
 
     def run(self) -> None:
@@ -21,10 +19,10 @@ class ScriptTask(LoginHandler):
         主要就是登录的模块
         :return:
         """
-        self.app_restart()
+        if not self.delay_pending_tasks():
+            self.app_restart()
         raise TaskEnd('ScriptTask end')
 
-
     def app_stop(self):
         logger.hr('App stop')
         self.device.app_stop()
@@ -44,6 +42,21 @@ class ScriptTask(LoginHandler):
         # self.config.task_delay(server_update=True)
         self.set_next_run(task='Restart', success=True, finish=True, server=True)
 
+    def delay_pending_tasks(self) -> bool:
+        """
+        周三更新游戏的时候延迟
+        @return:
+        """
+        datetime_now = datetime.now()
+        if not (datetime_now.weekday() == 2 and 6 <= datetime_now.hour <= 8):
+            return False
+        logger.info("The game server is updating, delay the pending tasks to 9:00")
+        logger.warning('Delay pending tasks')
+        # running 中的必然是 Restart
+        for task in self.config.pending_task:
+            print(task.command)
+            self.set_next_run(task=task.command, target=datetime_now.replace(hour=9, minute=0, second=0, microsecond=0))
+        return True
 
 
 if __name__ == '__main__':
@@ -53,7 +66,8 @@ if __name__ == '__main__':
     config = Config('oas1')
     device = Device(config)
     task = ScriptTask(config, device)
-    task.harvest()
+    task.config.update_scheduler()
+    task.delay_pending_tasks()
     # task.screenshot()
     # print(task.appear_then_click(task.I_LOGIN_SCROOLL_CLOSE, threshold=0.9))
 

+ 1 - 1
tasks/SoulsTidy/script_task.py

@@ -74,7 +74,7 @@ class ScriptTask(GameUi, SoulsTidyAssets):
                 continue
             if feed_count >= 3:
                 break
-            if self.appear_then_click(self.I_ST_FEED_NOW, interval=1.9):
+            if self.appear_then_click(self.I_ST_FEED_NOW, interval=3.5):
                 feed_count += 1
                 continue
         logger.info('Feed greed ghost done')