mirror of
https://gitee.com/sui-feng-cb/AzurLaneAutoScript1
synced 2026-03-12 17:57:01 +08:00
Add: Alas stop when have update
This commit is contained in:
25
alas.py
25
alas.py
@@ -1,5 +1,6 @@
|
||||
import os
|
||||
import re
|
||||
import threading
|
||||
import time
|
||||
from datetime import datetime
|
||||
|
||||
@@ -15,6 +16,9 @@ from module.logger import logger
|
||||
|
||||
|
||||
class AzurLaneAutoScript:
|
||||
|
||||
stop_event: threading.Event
|
||||
|
||||
def __init__(self, config_name='alas'):
|
||||
self.config_name = config_name
|
||||
ConfigUpdater().update_config(config_name)
|
||||
@@ -269,8 +273,7 @@ class AzurLaneAutoScript:
|
||||
GemsFarming(config=self.config, device=self.device).run(
|
||||
name=self.config.Campaign_Name, folder=self.config.Campaign_Event, mode=self.config.Campaign_Mode)
|
||||
|
||||
@staticmethod
|
||||
def wait_until(future):
|
||||
def wait_until(self, future):
|
||||
"""
|
||||
Wait until a specific time.
|
||||
|
||||
@@ -278,10 +281,17 @@ class AzurLaneAutoScript:
|
||||
future (datetime):
|
||||
"""
|
||||
seconds = future.timestamp() - datetime.now().timestamp() + 1
|
||||
if seconds > 0:
|
||||
time.sleep(seconds)
|
||||
else:
|
||||
if seconds <= 0:
|
||||
logger.warning(f'Wait until {str(future)}, but sleep length < 0, skip waiting')
|
||||
|
||||
if hasattr(self, 'stop_event'):
|
||||
self.stop_event.wait(seconds)
|
||||
if self.stop_event.is_set():
|
||||
logger.info("Update event detected")
|
||||
logger.info(f"Alas [{self.config_name}] exited.")
|
||||
exit(0)
|
||||
else:
|
||||
time.sleep(seconds)
|
||||
|
||||
def get_next_task(self):
|
||||
"""
|
||||
@@ -320,6 +330,11 @@ class AzurLaneAutoScript:
|
||||
failure_record = {}
|
||||
|
||||
while 1:
|
||||
if hasattr(self, 'stop_event'):
|
||||
if self.stop_event.is_set():
|
||||
logger.info("Update event detected")
|
||||
logger.info(f"Alas [{self.config_name}] exited.")
|
||||
break
|
||||
task = self.get_next_task()
|
||||
|
||||
# Skip first restart
|
||||
|
||||
@@ -63,7 +63,7 @@ class AlasManager:
|
||||
if not self.alive:
|
||||
self._process = Process(
|
||||
target=AlasManager.run_alas,
|
||||
args=(self.config_name, self.log_queue, func))
|
||||
args=(self.config_name, func, self.log_queue, updater.event,))
|
||||
self._process.start()
|
||||
self.thd_log_queue_handler = Thread(
|
||||
target=self._thread_log_queue_handler)
|
||||
@@ -112,7 +112,7 @@ class AlasManager:
|
||||
return cls.all_alas[config_name]
|
||||
|
||||
@staticmethod
|
||||
def run_alas(config_name, q: queue.Queue, func: str) -> None:
|
||||
def run_alas(config_name, func: str, q: queue.Queue, e: threading.Event) -> None:
|
||||
# Setup logger
|
||||
qh = QueueHandler(q)
|
||||
formatter = logging.Formatter(
|
||||
@@ -130,6 +130,7 @@ class AlasManager:
|
||||
# Run alas
|
||||
if func == 'Alas':
|
||||
from alas import AzurLaneAutoScript
|
||||
AzurLaneAutoScript.stop_event = e
|
||||
AzurLaneAutoScript(config_name=config_name).loop()
|
||||
elif func == 'Daemon':
|
||||
from module.daemon.daemon import AzurLaneDaemon
|
||||
|
||||
Reference in New Issue
Block a user