1
This commit is contained in:
@@ -1167,12 +1167,35 @@ class TaskQueue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 计算总待执行数:队列中的任务数 + 当前任务中剩余的步骤数
|
||||||
|
let totalPendingCount = queue ? queue.size() : 0;
|
||||||
|
|
||||||
|
// 如果当前任务存在且有进度信息,计算剩余步骤数
|
||||||
|
if (currentTask && currentTask.progress !== null && currentTask.progress !== undefined) {
|
||||||
|
// 根据进度计算剩余步骤(假设每个步骤占一定百分比)
|
||||||
|
// 如果进度是 45%,剩余就是 55%,可以估算剩余步骤数
|
||||||
|
const remainingProgress = 100 - currentTask.progress;
|
||||||
|
// 如果进度是整数百分比,可以估算剩余步骤
|
||||||
|
// 例如:如果进度是 45%,剩余 55%,假设每步 10%,则剩余约 5-6 步
|
||||||
|
// 这里简化处理:如果有进度且小于 100%,至少还有 1 个步骤在执行
|
||||||
|
if (remainingProgress > 0) {
|
||||||
|
// 估算剩余步骤数(基于进度百分比,假设每步约 10-20%)
|
||||||
|
// 更准确的方式是从任务参数中获取步骤信息
|
||||||
|
const estimatedRemainingSteps = Math.max(1, Math.ceil(remainingProgress / 10));
|
||||||
|
totalPendingCount += estimatedRemainingSteps;
|
||||||
|
}
|
||||||
|
} else if (currentTask && currentTask.currentStep) {
|
||||||
|
// 如果只有步骤信息但没有进度,至少还有 1 个步骤在执行
|
||||||
|
totalPendingCount += 1;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
sn_code,
|
sn_code,
|
||||||
currentTask,
|
currentTask,
|
||||||
pendingTasks,
|
pendingTasks,
|
||||||
nextTaskTime,
|
nextTaskTime,
|
||||||
pendingCount: queue ? queue.size() : 0,
|
pendingCount: queue ? queue.size() : 0, // 队列中的任务数
|
||||||
|
totalPendingCount: totalPendingCount, // 总待执行数(包括当前任务的剩余步骤)
|
||||||
mqttTopic: `task_status_${sn_code}`,
|
mqttTopic: `task_status_${sn_code}`,
|
||||||
timestamp: new Date().toISOString()
|
timestamp: new Date().toISOString()
|
||||||
};
|
};
|
||||||
@@ -1184,6 +1207,7 @@ class TaskQueue {
|
|||||||
pendingTasks: [],
|
pendingTasks: [],
|
||||||
nextTaskTime: null,
|
nextTaskTime: null,
|
||||||
pendingCount: 0,
|
pendingCount: 0,
|
||||||
|
totalPendingCount: 0,
|
||||||
mqttTopic: `task_status_${sn_code}`,
|
mqttTopic: `task_status_${sn_code}`,
|
||||||
timestamp: new Date().toISOString()
|
timestamp: new Date().toISOString()
|
||||||
};
|
};
|
||||||
@@ -1213,7 +1237,24 @@ class TaskQueue {
|
|||||||
});
|
});
|
||||||
|
|
||||||
await mqttClient.publish(topic, message);
|
await mqttClient.publish(topic, message);
|
||||||
console.log(`[任务队列] 已发送任务状态摘要到 ${sn_code}: 当前任务=${summary.currentTask ? '有' : '无'}, 待执行=${summary.pendingCount}个`);
|
|
||||||
|
// 改进日志输出,显示更详细的任务信息
|
||||||
|
if (summary.currentTask) {
|
||||||
|
const task = summary.currentTask;
|
||||||
|
const progressInfo = task.progress !== null && task.progress !== undefined
|
||||||
|
? `进度: ${task.progress}%`
|
||||||
|
: '';
|
||||||
|
const stepInfo = task.currentStep
|
||||||
|
? `步骤: ${task.currentStep}`
|
||||||
|
: '';
|
||||||
|
const detailInfo = [progressInfo, stepInfo].filter(Boolean).join(', ');
|
||||||
|
const detailStr = detailInfo ? ` (${detailInfo})` : '';
|
||||||
|
// 使用总待执行数(包括当前任务的剩余步骤)
|
||||||
|
const totalCount = summary.totalPendingCount !== undefined ? summary.totalPendingCount : summary.pendingCount;
|
||||||
|
console.log(`[任务队列] 已发送任务状态摘要到 ${sn_code}: 当前任务=${task.taskName || task.taskType || '未知任务'}${detailStr}, 待执行=${totalCount}个`);
|
||||||
|
} else {
|
||||||
|
console.log(`[任务队列] 已发送任务状态摘要到 ${sn_code}: 当前任务=无, 待执行=${summary.pendingCount}个`);
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// 通知失败不影响任务执行,只记录日志
|
// 通知失败不影响任务执行,只记录日志
|
||||||
console.warn(`[任务队列] 发送任务状态摘要失败:`, error.message);
|
console.warn(`[任务队列] 发送任务状态摘要失败:`, error.message);
|
||||||
|
|||||||
Reference in New Issue
Block a user