重置残留的Running状态任务为Pending,确保程序异常关闭后恢复状态

This commit is contained in:
tian 2026-02-03 22:56:39 +08:00
parent 2930ea71da
commit f9f8b5f9aa
2 changed files with 38 additions and 1 deletions

View File

@ -4,7 +4,7 @@
### [2026/2/3]
1. [ ] (优化)预计算高亮正确,结果高亮错误,高亮了很多不相干的同名物体
1. [x] (优化)预计算高亮正确,结果高亮错误,高亮了很多不相干的同名物体
2. [ ] BUG预计算一个目标物体161帧碰撞机制有问题
3. [ ] BUG吊装路径终点前的一段拐弯通行空间方向不对
4. [ ] BUG批处理时杀死程序重新打开有执行中的任务但删除选中没激活再运行批处理收到停止信号结束

View File

@ -64,6 +64,43 @@ namespace NavisworksTransport.Core
{
_database = pathPlanningManager?.GetPathDatabase();
LogManager.Info("BatchQueueManager已设置PathPlanningManager");
// 重置残留的Running状态任务程序异常关闭后重启
_ = ResetStaleRunningItemsAsync();
}
/// <summary>
/// 重置残留的Running状态任务为Pending
/// 用于程序异常关闭后重启时恢复状态
/// </summary>
private async Task ResetStaleRunningItemsAsync()
{
try
{
if (_database == null) return;
var allItems = await _database.GetBatchQueueItemsAsync(statusFilter: BatchQueueStatus.All, limit: 1000);
var staleItems = allItems.Where(item => item.Status == BatchQueueStatus.Running).ToList();
if (staleItems.Count > 0)
{
LogManager.Info($"[批处理队列] 发现 {staleItems.Count} 个残留的Running状态任务重置为Pending");
foreach (var item in staleItems)
{
item.Status = BatchQueueStatus.Pending;
item.StartTime = null;
item.EndTime = null;
item.ErrorMessage = null;
await _database.UpdateBatchQueueItemAsync(item);
LogManager.Info($"[批处理队列] 已重置任务: {item.PathRouteName} (ID: {item.Id})");
}
}
}
catch (Exception ex)
{
LogManager.Error($"[批处理队列] 重置残留Running任务失败: {ex.Message}");
}
}
/// <summary>