Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions module/config/argument/args.json
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,20 @@
"display": "hide"
}
},
"MidnightRandomDelay": {
"Enable": {
"type": "checkbox",
"value": false,
"option": [
true,
false
]
},
"MaxSeconds": {
"type": "input",
"value": 300
}
},
"Storage": {
"Storage": {
"type": "storage",
Expand Down
24 changes: 24 additions & 0 deletions module/config/argument/argument.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,30 @@ Scheduler:
ServerUpdate:
value: 00:00
display: hide
Restart:
Scheduler:
Enable:
type: checkbox
value: false
option: [ true, false ]
NextRun: 2020-01-01 00:00:00
Command: Restart
SuccessInterval:
value: 0
display: hide
FailureInterval:
value: 120
display: hide
ServerUpdate:
value: 00:00
display: hide
MidnightRandomDelay:
Enable:
type: checkbox
value: false
option: [ true, false ]
MaxSeconds:
value: 300
Emulator:
Serial:
value: auto
Expand Down
10 changes: 10 additions & 0 deletions module/config/config_generated.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ class GeneratedConfig:
Scheduler_FailureInterval = 120
Scheduler_ServerUpdate = '00:00'

# Group `Restart`
Restart_Scheduler_Enable = False
Restart_Scheduler_NextRun = datetime.datetime(2020, 1, 1, 0, 0)
Restart_Scheduler_Command = 'Restart'
Restart_Scheduler_SuccessInterval = 0
Restart_Scheduler_FailureInterval = 120
Restart_Scheduler_ServerUpdate = '00:00'
Restart_MidnightRandomDelay_Enable = False # True, False
Restart_MidnightRandomDelay_MaxSeconds = 300
Comment on lines +20 to +22

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这怎么有三个层级的?这不对吧

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

前面生成的多余的修了(还没提交)。

这里有三个层级是因为配置里面是这样写的:

Restart:
  MidnightRandomDelay:
    Enable:
      type: checkbox
      value: false
      option: [ true, false ]
    MaxSeconds:
      value: 300

可以工作,并且语义也足够清晰。一定要改成两层的也可以改


# Group `Emulator`
Emulator_Serial = 'auto'
Emulator_PackageName = 'auto' # auto, com.bilibili.azurlane, com.YoStarEN.AzurLane, com.YoStarJP.AzurLane, com.hkmanjuu.azurlane.gp, com.bilibili.blhx.huawei, com.bilibili.blhx.honor, com.bilibili.blhx.mi, com.tencent.tmgp.bilibili.blhx, com.bilibili.blhx.baidu, com.bilibili.blhx.qihoo, com.bilibili.blhx.nearme.gamecenter, com.bilibili.blhx.vivo, com.bilibili.blhx.mz, com.bilibili.blhx.dl, com.bilibili.blhx.lenovo, com.bilibili.blhx.uc, com.bilibili.blhx.mzw, com.yiwu.blhx.yx15, com.bilibili.blhx.m4399, com.bilibili.blhx.bilibiliMove, com.hkmanjuu.azurlane.gp.mc
Expand Down
22 changes: 22 additions & 0 deletions module/config/i18n/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -1345,6 +1345,28 @@
"multi": "Coalition Battle"
}
},
"Restart": {
"_info": {
"name": "Restart Settings",
"help": ""
}
},
"MidnightRandomDelay": {
"_info": {
"name": "Midnight Random Delay",
"help": ""
},
"Enable": {
"name": "Midnight Random Delay",
"help": "Enable to add a random delay before restart at midnight, reducing network load near 00:00",
"True": "Enable",
"False": "Disable"
},
"MaxSeconds": {
"name": "Max Delay (seconds)",
"help": "Maximum random delay in seconds, a random value between 0 and this will be used"
}
},
"Commission": {
"_info": {
"name": "Commission Settings",
Expand Down
22 changes: 22 additions & 0 deletions module/config/i18n/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -1345,6 +1345,28 @@
"multi": "multi"
}
},
"Restart": {
"_info": {
"name": "再起動設定",
"help": ""
}
},
"MidnightRandomDelay": {
"_info": {
"name": "深夜ランダム遅延",
"help": ""
},
"Enable": {
"name": "深夜ランダム遅延",
"help": "深夜0:00付近の再起動時にランダムな遅延を追加し、ネットワーク負荷を軽減します",
"True": "有効",
"False": "無効"
},
"MaxSeconds": {
"name": "最大遅延(秒)",
"help": "ランダム遅延の最大値(秒)、0からこの値の間でランダムに決定されます"
}
},
"Commission": {
"_info": {
"name": "Commission._info.name",
Expand Down
22 changes: 22 additions & 0 deletions module/config/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -1345,6 +1345,28 @@
"multi": "多队出击"
}
},
"Restart": {
"_info": {
"name": "重启设置",
"help": ""
}
},
"MidnightRandomDelay": {
"_info": {
"name": "午夜随机延迟",
"help": ""
},
"Enable": {
"name": "午夜随机延迟",
"help": "如遇半夜重启时卡网络可以尝试打开此开关,降低0:00附近的网络压力",
"True": "启用",
"False": "关闭"
},
"MaxSeconds": {
"name": "随机延迟上限",
"help": "延迟时间的最大值(秒),将在0到此值之间随机"
}
},
"Commission": {
"_info": {
"name": "委托",
Expand Down
22 changes: 22 additions & 0 deletions module/config/i18n/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -1345,6 +1345,28 @@
"multi": "多隊出擊"
}
},
"Restart": {
"_info": {
"name": "重啟設定",
"help": ""
}
},
"MidnightRandomDelay": {
"_info": {
"name": "午夜隨機延遲",
"help": ""
},
"Enable": {
"name": "午夜隨機延遲",
"help": "如遇半夜重啟時卡網路可以嘗試打開此開關,降低0:00附近的網路壓力",
"True": "啟用",
"False": "關閉"
},
"MaxSeconds": {
"name": "隨機延遲上限",
"help": "延遲時間的最大值(秒),將在0到此值之間隨機"
}
},
"Commission": {
"_info": {
"name": "委託",
Expand Down
14 changes: 14 additions & 0 deletions module/handler/login.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import random
from datetime import datetime
from typing import Union

import numpy as np
Expand Down Expand Up @@ -163,6 +165,18 @@ def app_start(self):

def app_restart(self):
logger.hr('App restart')
# Random delay when triggered at midnight to avoid server load spikes
# During this delay, other tasks are naturally blocked because
# Restart is the currently running task (highest priority at 0:00)
if self.config.Restart_MidnightRandomDelay_Enable:
max_delay = self.config.Restart_MidnightRandomDelay_MaxSeconds
now = datetime.now()
if now.hour == 0 and now.minute < 5 and max_delay > 0:
delay = random.randint(0, max_delay)
if delay > 0:
logger.info(f'Restart at midnight: random delay {delay}s'
f' (all tasks blocked)')
self.device.sleep(delay)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

需要时区换算

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已补充时区配置

self.device.app_stop()
self.device.app_start()
self.handle_app_login()
Expand Down