/// <summary> /// 构建T8任务 /// </summary> private void BuildServiceTask(T8ConfigItemEntity t8ConfigItem, CancellationToken ct) { try { ct.ThrowIfCancellationRequested(); ACreateTask createTaskService = AutoFacContainer.ResolveNamed <ACreateTask>(typeof(ServiceCreateTask).Name); T8TaskEntity t8Task = createTaskService.CreateTask(); if (t8Task != null) { //获取文件名 AFileName aFileNameService = AutoFacContainer.ResolveNamed <AFileName>(typeof(GeneralFileName).Name); t8Task.T8FileEntity.GeneralFileInfo = new T8FileInfoEntity { FileName = aFileNameService.FileName(t8Task.T8FileEntity), FilePath = aFileNameService.FileFullName(t8Task.T8FileEntity) }; T8TaskEntity taskEntityQueueItem; if (Completed_TaskQueue.TryGetValue(t8Task.GenerateTaskQueueKey, out taskEntityQueueItem)) { return; } if (Processing_TaskQueue.TryGetValue(t8Task.GenerateTaskQueueKey, out taskEntityQueueItem)) { return; } if (Error_TaskQueue.TryGetValue(t8Task.GenerateTaskQueueKey, out taskEntityQueueItem)) { return; } //添加到执行中队列 if (!Common.AddTaskToQueue(Processing_TaskQueue, t8Task, TaskQueueType.Processing)) { LogUtil.WriteLog($"任务队列[{t8Task.TaskTitle}]添加失败"); Common.SetTaskErrorStatus(t8Task, "添加Processing_TaskQueue失败"); Common.AddTaskToQueue(Error_TaskQueue, t8Task, TaskQueueType.Error); return; } //构造数据文件产品并执行 DbFileProductDirector director = new DbFileProductDirector(); ADbFileProductBuilder productBuilder = new DbFileProductBuilder(); director.ConstructProduct(productBuilder); DbFileProduct product = productBuilder.GetDbFileProduct(); product.Execute(t8Task, cts.Token); //任务结束 1从Processing_TaskQueue队列移走 2任务完成,移入Completed_TaskQueue队列 3任务失败,移入 if (Common.RemoveTaskFromQueue(Processing_TaskQueue, t8Task, TaskQueueType.Processing)) { if (t8Task.T8TaskStatus == T8TaskStatus.Complete) { Common.AddTaskToQueue(Completed_TaskQueue, t8Task, TaskQueueType.Completed); LogUtil.WriteLog($"T8任务[{t8Task.TaskTitle}]执行完成,转移到Completed_TaskQueue队列"); } else { Common.AddTaskToQueue(Error_TaskQueue, t8Task, TaskQueueType.Error); LogUtil.WriteLog($"T8任务[{t8Task.TaskTitle}]执行失败,转移到Error_TaskQueue队列,等待下次重试"); } } } else { LogUtil.WriteLog("创建任务实体失败"); } } catch (Exception ex) { LogUtil.WriteLog(ex); } }
/// <summary> /// 文件完全路径 /// </summary> /// <param name="t8FileEntity"></param> /// <returns></returns> public string FileFullName(T8FileEntity t8FileEntity) { return _AFileName.FileFullName(t8FileEntity); }