From 2b757e33ee6eddf2b0bf672fe9b07d5436eb5cf1 Mon Sep 17 00:00:00 2001 From: liujx54704 Date: Fri, 21 Feb 2025 20:10:22 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E5=A2=9E=E5=8A=A030=E5=88=86=E9=92=9F?= =?UTF-8?q?=E6=97=A0=E4=BB=BB=E5=8A=A1=E5=85=B3=E9=97=AD=E6=A8=A1=E6=8B=9F?= =?UTF-8?q?=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script.py | 14 +++++++++++++- tasks/Script/config_optimization.py | 2 ++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/script.py b/script.py index 85c28bc50..36eea42b3 100644 --- a/script.py +++ b/script.py @@ -35,6 +35,7 @@ class Script: def __init__(self, config_name: str ='oas') -> None: + self.device = None logger.hr('Start', level=0) self.server = None self.state_queue: Queue = None @@ -325,6 +326,14 @@ def get_next_task(self) -> str: if not self.wait_until(task.next_run): del_cached_property(self, 'config') continue + elif method == 'close_emulator': + logger.info('close emulator during wait') + if task.next_run > datetime.now() + timedelta(minutes=30): + self.device.emulator_stop() + self.device.release_during_wait() + if not self.wait_until(task.next_run): + del_cached_property(self, 'config') + continue else: logger.warning(f'Invalid Optimization_WhenTaskQueueEmpty: {method}, fallback to stay_there') self.device.release_during_wait() @@ -424,17 +433,20 @@ def loop(self): # logger.info('Server or network is recovered. Restart game client') # self.config.task_call('Restart') + if self.is_first_task: + self.device = Device(self.config) # Get task task = self.get_next_task() # 更新 gui的任务 # Init device and change server - _ = self.device + # _ = self.device # Skip first restart if self.is_first_task and task == 'Restart': logger.info('Skip task `Restart` at scheduler start') self.config.task_delay(task='Restart', success=True, server=True) del_cached_property(self, 'config') continue + self.device = Device(self.config) # Run logger.info(f'Scheduler: Start task `{task}`') diff --git a/tasks/Script/config_optimization.py b/tasks/Script/config_optimization.py index acc76064b..4231a4a76 100644 --- a/tasks/Script/config_optimization.py +++ b/tasks/Script/config_optimization.py @@ -9,6 +9,8 @@ class WhenTaskQueueEmpty(str, Enum): GOTO_MAIN = 'goto_main' CLOSE_GAME = 'close_game' + CLOSE_emulator = 'close_emulator' + class ScheduleRule(str, Enum): FILTER = 'Filter' # 默认的基于过滤器,(按照开发者设定的调度规则进行调度) From 4e1349e8128a2f7649929f3b947b88dc5f89d75d Mon Sep 17 00:00:00 2001 From: ljxun <591692130@qq.com> Date: Fri, 21 Feb 2025 23:08:29 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=97=A0=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E5=85=B3=E9=97=AD=E6=A8=A1=E6=8B=9F=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script.py | 5 ++++- tasks/Script/config_optimization.py | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/script.py b/script.py index 36eea42b3..2f3000c1a 100644 --- a/script.py +++ b/script.py @@ -328,8 +328,11 @@ def get_next_task(self) -> str: continue elif method == 'close_emulator': logger.info('close emulator during wait') - if task.next_run > datetime.now() + timedelta(minutes=30): + limit_time = self.config.script.optimization.limit_time + if task.next_run > datetime.now() + timedelta(hours=limit_time.hour, minutes=limit_time.minute, seconds=limit_time.second): self.device.emulator_stop() + else: + self.run('GotoMain') self.device.release_during_wait() if not self.wait_until(task.next_run): del_cached_property(self, 'config') diff --git a/tasks/Script/config_optimization.py b/tasks/Script/config_optimization.py index 4231a4a76..95ba8e08d 100644 --- a/tasks/Script/config_optimization.py +++ b/tasks/Script/config_optimization.py @@ -5,6 +5,7 @@ from pydantic import BaseModel, ValidationError, validator, Field from module.logger import logger +from tasks.Component.config_base import ConfigBase, Time class WhenTaskQueueEmpty(str, Enum): GOTO_MAIN = 'goto_main' @@ -26,5 +27,6 @@ class Optimization(BaseModel): description='task_hoarding_duration_help') when_task_queue_empty: WhenTaskQueueEmpty = Field(default=WhenTaskQueueEmpty.GOTO_MAIN, description='when_task_queue_empty_help') + limit_time: Time = Field(default=Time(minute=30), description='limit_time_help') schedule_rule: ScheduleRule = Field(default=ScheduleRule.FILTER, description='schedule_rule_help') From 6abe23d33bfdb6021f7126e377fbd604a23bc580 Mon Sep 17 00:00:00 2001 From: yEs1do Date: Sun, 23 Feb 2025 00:46:24 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E5=85=B3=E9=97=AD=E6=A8=A1=E6=8B=9F?= =?UTF-8?q?=E5=99=A8=E5=A2=9E=E5=8A=A0=E4=B8=A4=E7=A7=8D=E9=80=89=E9=A1=B9?= =?UTF-8?q?=EF=BC=9A=E5=9B=9E=E5=88=B0=E6=A1=8C=E9=9D=A2/=E5=85=B3?= =?UTF-8?q?=E9=97=AD=E6=B8=B8=E6=88=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script.py | 11 ++++++++--- tasks/Script/config_optimization.py | 3 ++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/script.py b/script.py index 2f3000c1a..d3ef2dea0 100644 --- a/script.py +++ b/script.py @@ -326,13 +326,18 @@ def get_next_task(self) -> str: if not self.wait_until(task.next_run): del_cached_property(self, 'config') continue - elif method == 'close_emulator': - logger.info('close emulator during wait') + elif method == 'close_emulator_or_goto_main' or method == 'close_emulator_or_close_game': limit_time = self.config.script.optimization.limit_time if task.next_run > datetime.now() + timedelta(hours=limit_time.hour, minutes=limit_time.minute, seconds=limit_time.second): + logger.info('Close emulator during wait') self.device.emulator_stop() else: - self.run('GotoMain') + if method == 'close_emulator_or_goto_main': + logger.info('Goto main page during wait') + self.run('GotoMain') + else: + logger.info('Close game during wait') + self.device.app_stop() self.device.release_during_wait() if not self.wait_until(task.next_run): del_cached_property(self, 'config') diff --git a/tasks/Script/config_optimization.py b/tasks/Script/config_optimization.py index 95ba8e08d..8db6e18d9 100644 --- a/tasks/Script/config_optimization.py +++ b/tasks/Script/config_optimization.py @@ -10,7 +10,8 @@ class WhenTaskQueueEmpty(str, Enum): GOTO_MAIN = 'goto_main' CLOSE_GAME = 'close_game' - CLOSE_emulator = 'close_emulator' + CLOSE_EMULATOR_OR_GOTO_MAIN = 'close_emulator_or_goto_main' + CLOSE_EMULATOR_OR_CLOSE_GAME = 'close_emulator_or_close_game' class ScheduleRule(str, Enum): From 273a7b8b3cff1263806fdecf582fe9441fddd537 Mon Sep 17 00:00:00 2001 From: yEs1do Date: Sun, 23 Feb 2025 22:18:45 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=85=B3=E9=97=AD?= =?UTF-8?q?=E6=B8=B8=E6=88=8F=E7=AD=89=E5=BE=85=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script.py | 69 ++++++++++++++--------------- tasks/Script/config_optimization.py | 3 +- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/script.py b/script.py index d3ef2dea0..ddfb94137 100644 --- a/script.py +++ b/script.py @@ -311,47 +311,46 @@ def get_next_task(self) -> str: logger.info(f'Wait until {task.next_run} for task `{task.command}`') # self.is_first_task = False method = self.config.script.optimization.when_task_queue_empty - if method == 'close_game': - logger.info('Close game during wait') - self.device.app_stop() - self.device.release_during_wait() - if not self.wait_until(task.next_run): - del_cached_property(self, 'config') - continue - self.run('Restart') - elif method == 'goto_main': - logger.info('Goto main page during wait') - self.run('GotoMain') - self.device.release_during_wait() - if not self.wait_until(task.next_run): - del_cached_property(self, 'config') - continue - elif method == 'close_emulator_or_goto_main' or method == 'close_emulator_or_close_game': - limit_time = self.config.script.optimization.limit_time - if task.next_run > datetime.now() + timedelta(hours=limit_time.hour, minutes=limit_time.minute, seconds=limit_time.second): - logger.info('Close emulator during wait') - self.device.emulator_stop() - else: - if method == 'close_emulator_or_goto_main': - logger.info('Goto main page during wait') - self.run('GotoMain') - else: - logger.info('Close game during wait') - self.device.app_stop() - self.device.release_during_wait() - if not self.wait_until(task.next_run): - del_cached_property(self, 'config') - continue + close_game_limit_time = self.config.script.optimization.close_game_limit_time + close_emulator_limit_time = self.config.script.optimization.close_emulator_limit_time + + if method == 'goto_main': + self._handle_goto_main() + elif method == 'close_game': + self._handle_close_game(task, close_game_limit_time) + elif method in ['close_emulator_or_goto_main', 'close_emulator_or_close_game']: + self._handle_close_emulator_or(task, close_game_limit_time, close_emulator_limit_time, method) else: logger.warning(f'Invalid Optimization_WhenTaskQueueEmpty: {method}, fallback to stay_there') - self.device.release_during_wait() - if not self.wait_until(task.next_run): - del_cached_property(self, 'config') - continue + + self.device.release_during_wait() + if not self.wait_until(task.next_run): + del_cached_property(self, 'config') + continue break return task.command + def _handle_goto_main(self): + logger.info('Goto main page during wait') + self.run('GotoMain') + + def _handle_close_game(self, task, close_game_limit_time): + if task.next_run > datetime.now() + timedelta(hours=close_game_limit_time.hour, minutes=close_game_limit_time.minute, seconds=close_game_limit_time.second): + logger.info('Close game during wait') + self.device.app_stop() + else: + self._handle_goto_main(task) + + def _handle_close_emulator_or(self, task, close_game_limit_time, close_emulator_limit_time, method): + if task.next_run > datetime.now() + timedelta(hours=close_emulator_limit_time.hour, minutes=close_emulator_limit_time.minute, seconds=close_emulator_limit_time.second): + logger.info('Close emulator during wait') + self.device.emulator_stop() + elif method == 'close_emulator_or_goto_main': + self._handle_goto_main(task) + else: + self._handle_close_game(task, close_game_limit_time) + def run(self, command: str) -> bool: """ diff --git a/tasks/Script/config_optimization.py b/tasks/Script/config_optimization.py index 8db6e18d9..7de5a9a16 100644 --- a/tasks/Script/config_optimization.py +++ b/tasks/Script/config_optimization.py @@ -28,6 +28,7 @@ class Optimization(BaseModel): description='task_hoarding_duration_help') when_task_queue_empty: WhenTaskQueueEmpty = Field(default=WhenTaskQueueEmpty.GOTO_MAIN, description='when_task_queue_empty_help') - limit_time: Time = Field(default=Time(minute=30), description='limit_time_help') + close_game_limit_time: Time = Field(default=Time(minute=10), description='关闭游戏等待时间') + close_emulator_limit_time: Time = Field(default=Time(minute=30), description='关闭模拟器等待时间') schedule_rule: ScheduleRule = Field(default=ScheduleRule.FILTER, description='schedule_rule_help') From 251f2a9ec8df0ce9e24120a83c6eb3cd42eaed89 Mon Sep 17 00:00:00 2001 From: yEs1do Date: Sun, 23 Feb 2025 23:32:02 +0800 Subject: [PATCH 5/6] fix --- script.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/script.py b/script.py index ddfb94137..3b3d182fa 100644 --- a/script.py +++ b/script.py @@ -340,14 +340,14 @@ def _handle_close_game(self, task, close_game_limit_time): logger.info('Close game during wait') self.device.app_stop() else: - self._handle_goto_main(task) + self._handle_goto_main() def _handle_close_emulator_or(self, task, close_game_limit_time, close_emulator_limit_time, method): if task.next_run > datetime.now() + timedelta(hours=close_emulator_limit_time.hour, minutes=close_emulator_limit_time.minute, seconds=close_emulator_limit_time.second): logger.info('Close emulator during wait') self.device.emulator_stop() elif method == 'close_emulator_or_goto_main': - self._handle_goto_main(task) + self._handle_goto_main() else: self._handle_close_game(task, close_game_limit_time) From b7bcc2c4543210a506dbd2d22a9a77be500f10b8 Mon Sep 17 00:00:00 2001 From: yEs1do Date: Sun, 27 Jul 2025 22:55:22 +0800 Subject: [PATCH 6/6] =?UTF-8?q?self.device=20=E5=85=BC=E9=A1=BE=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E4=B8=8E=E9=87=8D=E5=90=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/script.py b/script.py index 3b3d182fa..2bf90ab80 100644 --- a/script.py +++ b/script.py @@ -35,7 +35,7 @@ class Script: def __init__(self, config_name: str ='oas') -> None: - self.device = None + self._emulator_down = False logger.hr('Start', level=0) self.server = None self.state_queue: Queue = None @@ -346,6 +346,7 @@ def _handle_close_emulator_or(self, task, close_game_limit_time, close_emulator_ if task.next_run > datetime.now() + timedelta(hours=close_emulator_limit_time.hour, minutes=close_emulator_limit_time.minute, seconds=close_emulator_limit_time.second): logger.info('Close emulator during wait') self.device.emulator_stop() + self._emulator_down = True # 标记 elif method == 'close_emulator_or_goto_main': self._handle_goto_main() else: @@ -440,8 +441,6 @@ def loop(self): # logger.info('Server or network is recovered. Restart game client') # self.config.task_call('Restart') - if self.is_first_task: - self.device = Device(self.config) # Get task task = self.get_next_task() # 更新 gui的任务 @@ -453,7 +452,11 @@ def loop(self): self.config.task_delay(task='Restart', success=True, server=True) del_cached_property(self, 'config') continue - self.device = Device(self.config) + if self._emulator_down: + self.device = Device(self.config) + self._emulator_down = False + else: + _ = self.device # 使用缓存 # Run logger.info(f'Scheduler: Start task `{task}`')