feat: 任务抢占+归还(抢占任务结束后自动重启被抢占任务)+ 修复抢占死锁(stop_device 移出锁块)+ wait 步骤可中断 + 循环块新增一直循环模式(配合定时启动+停止实现全天候养号)
This commit is contained in:
+18
-2
@@ -502,14 +502,30 @@ class GenericStepsWorker(BaseWorker):
|
||||
def _exec_wait(self, d, params, depth=0):
|
||||
min_s = float(params.get("min", 1.0))
|
||||
max_s = float(params.get("max", 3.0))
|
||||
random_sleep(min_s, max_s)
|
||||
# 分片 sleep:每 0.5s 检查停止/超时信号,抢占任务能及时接管(纯 sleep 无法中断)
|
||||
total = random.uniform(min_s, max_s)
|
||||
end = time.time() + total
|
||||
while time.time() < end:
|
||||
if self.stopped() or self.is_time_up():
|
||||
return
|
||||
time.sleep(min(0.5, end - time.time()))
|
||||
|
||||
def _exec_loop(self, d, params, depth=0):
|
||||
children = params.get("children", [])
|
||||
if not children:
|
||||
return
|
||||
mode = params.get("loop_mode", "rounds")
|
||||
if mode == "time":
|
||||
if mode == "forever":
|
||||
# 一直循环:无限跑直到任务被外部停止(定时停止 cron / 运行时长上限 / 手动停止)。
|
||||
# 配合"定时启动+停止"调度(如 9:00 启动 / 18:00 停止)实现全天候运行。
|
||||
i = 0
|
||||
while not self.stopped() and not self.is_time_up():
|
||||
i += 1
|
||||
self.set_action(f"循环第 {i} 轮(持续)")
|
||||
if i % 10 == 0 or i <= 2:
|
||||
_log.info(f"[{self.serial}] loop 第 {i} 轮(持续运行)")
|
||||
self._exec_steps(d, children, depth + 1)
|
||||
elif mode == "time":
|
||||
# 按时间循环:跑满 loop_duration 秒,同时受全局 stopped/max_duration 约束
|
||||
duration = float(params.get("loop_duration", 0) or 0)
|
||||
if duration <= 0:
|
||||
|
||||
Reference in New Issue
Block a user