1
This commit is contained in:
@@ -585,7 +585,9 @@ class TaskQueue {
|
||||
|
||||
// 推送设备工作状态(任务开始执行)
|
||||
const summary = await this.getTaskStatusSummary(task.sn_code);
|
||||
await deviceWorkStatusNotifier.sendDeviceWorkStatus(task.sn_code, summary);
|
||||
await deviceWorkStatusNotifier.sendDeviceWorkStatus(task.sn_code, summary, {
|
||||
currentCommand: summary.currentCommand || null
|
||||
});
|
||||
|
||||
// 使用注册的任务处理器执行任务
|
||||
const handler = this.taskHandlers.get(task.taskType);
|
||||
@@ -660,7 +662,9 @@ class TaskQueue {
|
||||
|
||||
// 推送设备工作状态(任务失败)
|
||||
const summary = await this.getTaskStatusSummary(task.sn_code);
|
||||
await deviceWorkStatusNotifier.sendDeviceWorkStatus(task.sn_code, summary);
|
||||
await deviceWorkStatusNotifier.sendDeviceWorkStatus(task.sn_code, summary, {
|
||||
currentCommand: summary.currentCommand || null
|
||||
});
|
||||
} catch (dbError) {
|
||||
console.error(`[任务队列] 更新任务失败状态到数据库失败:`, dbError);
|
||||
}
|
||||
@@ -1165,6 +1169,37 @@ class TaskQueue {
|
||||
}
|
||||
}
|
||||
|
||||
// 获取当前正在执行的指令(从数据库查询状态为 running 的指令)
|
||||
let currentCommand = null;
|
||||
try {
|
||||
const taskCommandsModel = db.getModel('task_commands');
|
||||
// 查找该设备下当前正在执行的指令(通过关联的 task_id 查找)
|
||||
if (currentTask && currentTask.taskId) {
|
||||
const runningCommand = await taskCommandsModel.findOne({
|
||||
where: {
|
||||
task_id: currentTask.taskId,
|
||||
status: 'running'
|
||||
},
|
||||
order: [['id', 'DESC']]
|
||||
});
|
||||
|
||||
if (runningCommand) {
|
||||
const cmdData = runningCommand.toJSON();
|
||||
currentCommand = {
|
||||
command_id: cmdData.id,
|
||||
command_name: cmdData.command_name || '执行指令',
|
||||
command_type: cmdData.command_type || '',
|
||||
command_params: cmdData.command_params || cmdData.params || {},
|
||||
progress: cmdData.progress || 0,
|
||||
currentStep: cmdData.current_step || '',
|
||||
startTime: cmdData.start_time || cmdData.created_time || new Date().toISOString()
|
||||
};
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`[任务队列] 查询当前执行指令失败:`, error);
|
||||
}
|
||||
|
||||
// 计算总待执行数:队列中的任务数 + 当前任务中剩余的步骤数
|
||||
let totalPendingCount = queue ? queue.size() : 0;
|
||||
|
||||
@@ -1190,6 +1225,7 @@ class TaskQueue {
|
||||
return {
|
||||
sn_code,
|
||||
currentTask,
|
||||
currentCommand, // 当前正在执行的指令
|
||||
pendingTasks,
|
||||
nextTaskTime,
|
||||
pendingCount: queue ? queue.size() : 0, // 队列中的任务数
|
||||
@@ -1202,6 +1238,7 @@ class TaskQueue {
|
||||
return {
|
||||
sn_code,
|
||||
currentTask: null,
|
||||
currentCommand: null,
|
||||
pendingTasks: [],
|
||||
nextTaskTime: null,
|
||||
pendingCount: 0,
|
||||
|
||||
Reference in New Issue
Block a user