JobProcesser.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826
  1. using Aitex.Core.RT.Log;
  2. using MECF.Framework.Common.Jobs;
  3. using System;
  4. using System.Collections.Generic;
  5. using MECF.Framework.Common.Equipment;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using Aitex.Core.Common;
  10. using MECF.Framework.Common.SubstrateTrackings;
  11. using MECF.Framework.Common.DBCore;
  12. using Aitex.Core.RT.DataCenter;
  13. using Aitex.Core.Util;
  14. using CyberX8_RT.Modules;
  15. using CyberX8_RT.Schedulers;
  16. using Aitex.Core.RT.SCCore;
  17. using MECF.Framework.Common.RecipeCenter;
  18. using Aitex.Core.RT.RecipeCenter;
  19. using Aitex.Common.Util;
  20. using System.Collections.Concurrent;
  21. using MECF.Framework.Common.WaferHolder;
  22. using CyberX8_RT.Modules.Loader;
  23. using SecsGem.Core.ItemModel;
  24. using CyberX8_RT.Devices.EFEM;
  25. namespace CyberX8_RT.Dispatch
  26. {
  27. public class JobProcesser : Singleton<JobProcesser>
  28. {
  29. #region 常量
  30. private const string PRODUCTION = "Production";
  31. private const string SEQUENCE_TYPE = "SequenceType";
  32. #endregion
  33. #region 内部变量
  34. /// <summary>
  35. /// control jobs
  36. /// </summary>
  37. private List<ControlJobInfo> _lstControlJobs = new List<ControlJobInfo>();
  38. /// <summary>
  39. /// process jobs
  40. /// </summary>
  41. private List<ProcessJobInfo> _lstProcessJobs = new List<ProcessJobInfo>();
  42. private SchedulerFACallback _faCallback;
  43. private SchedulerDBCallback _dbCallback;
  44. private Dictionary<string, ControlJobInfo> _loadportControlJobDic = new Dictionary<string, ControlJobInfo>();
  45. /// <summary>
  46. /// recipe processjob集合(key-recipe ppid,value-Process job集合)
  47. /// </summary>
  48. private ConcurrentDictionary<string, List<ProcessJobInfo>> _recipeProcessJobs = new ConcurrentDictionary<string, List<ProcessJobInfo>>();
  49. /// <summary>
  50. /// recipe集合
  51. /// </summary>
  52. private List<string> _recipeList = new List<string>();
  53. /// <summary>
  54. /// recipe锁
  55. /// </summary>
  56. private object _recipeLocker = new object();
  57. #endregion
  58. #region 属性
  59. /// <summary>
  60. /// ControlJob集合
  61. /// </summary>
  62. public List<ControlJobInfo> ControlJobInfos { get { return _lstControlJobs; } }
  63. /// <summary>
  64. /// ProcessJob集合
  65. /// </summary>
  66. public List<ProcessJobInfo> ProcessJobInfos { get { return _lstProcessJobs; } }
  67. #endregion
  68. /// <summary>
  69. /// 构造函数
  70. /// </summary>
  71. public JobProcesser()
  72. {
  73. _faCallback = new SchedulerFACallback();
  74. _dbCallback = new SchedulerDBCallback();
  75. InitializeData();
  76. }
  77. /// <summary>
  78. /// 初始化数据
  79. /// </summary>
  80. private void InitializeData()
  81. {
  82. for (int i = 1; i <= 3; i++)
  83. {
  84. _loadportControlJobDic[$"LP{i}"] = null;
  85. string lp = $"LP{i}";
  86. DATA.Subscribe($"{lp}.CurrentControlJob", () => _loadportControlJobDic[lp], SubscriptionAttribute.FLAG.IgnoreSaveDB);
  87. }
  88. DATA.Subscribe("Scheduler.CjNameList", () => Array.ConvertAll(_lstControlJobs.ToArray(), x => x.Name.ToString()).ToList(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  89. }
  90. /// <summary>
  91. /// 创建任务
  92. /// </summary>
  93. /// <param name="param"></param>
  94. /// <param name="reason"></param>
  95. /// <returns></returns>
  96. public bool CreateJob(Dictionary<string, object> param, out string reason)
  97. {
  98. reason = "";
  99. string[] slotSequence = (string[])param["SlotSequence"];
  100. string jobId = (string)param["JobId"];
  101. string module = (string)param["Module"];
  102. if (string.IsNullOrEmpty(jobId))
  103. {
  104. jobId = "CJ_Local_" + module;
  105. }
  106. string lotId = jobId;
  107. if (param.ContainsKey("LotId"))
  108. lotId = (string)param["LotId"];
  109. int cycleNumber = param.ContainsKey("CycleNumber") ? (int)param["CycleNumber"] : 1;
  110. if (slotSequence.Length != SC.GetValue<int>("EFEM.LoadPort.SlotNumber"))
  111. {
  112. reason = $"slot sequence parameter not valid, length is {slotSequence.Length}, should be {SC.GetValue<int>("EFEM.LoadPort.SlotNumber")}";
  113. LOG.WriteLog(eEvent.WARN_ROUTER, ModuleName.System.ToString(), reason);
  114. return false;
  115. }
  116. string sequenceType = PRODUCTION;
  117. if (param.ContainsKey(SEQUENCE_TYPE))
  118. {
  119. sequenceType = param[SEQUENCE_TYPE].ToString();
  120. }
  121. ModuleName lpModule = ModuleHelper.Converter(module);
  122. if (!ModuleHelper.IsLoadPort(lpModule))
  123. {
  124. reason = $"{module} should be LoadPort";
  125. LOG.WriteLog(eEvent.WARN_ROUTER, ModuleName.System.ToString(), reason);
  126. return false;
  127. }
  128. if (_lstControlJobs.Exists(x => x.Name == jobId))
  129. {
  130. reason = $"{jobId} already created";
  131. LOG.WriteLog(eEvent.WARN_ROUTER, ModuleName.System.ToString(), reason);
  132. return false;
  133. }
  134. ControlJobInfo cj = new ControlJobInfo();
  135. cj.Name = jobId;
  136. cj.Module = module;
  137. cj.LotName = lotId;
  138. cj.LotInnerId = Guid.NewGuid();
  139. cj.LotWafers = new List<WaferInfo>();
  140. cj.SetState(EnumControlJobState.WaitingForStart);
  141. cj.SequenceNameList = slotSequence;
  142. cj.CycleNumber = cycleNumber;
  143. Dictionary<string, bool[]> seqSlot = new Dictionary<string, bool[]>();
  144. Dictionary<string, List<Tuple<ModuleName, int>>> seqSlotWafers = new Dictionary<string, List<Tuple<ModuleName, int>>>();
  145. Dictionary<string, string> indexSequence = new Dictionary<string, string>();
  146. bool enableGroupBySequence = SC.GetValue<bool>("Scheduler.GroupWaferBySequence");
  147. int waferCount = 0;
  148. for (int i = 0; i < SC.GetValue<int>("EFEM.LoadPort.SlotNumber"); i++)
  149. {
  150. if (string.IsNullOrEmpty(slotSequence[i]) || string.IsNullOrEmpty(slotSequence[i].Trim()))
  151. continue;
  152. string groupName = enableGroupBySequence ? slotSequence[i].Trim() : i.ToString();
  153. indexSequence[groupName] = slotSequence[i];
  154. if (!seqSlot.ContainsKey(groupName))
  155. {
  156. seqSlot[groupName] = new bool[SC.GetValue<int>("EFEM.LoadPort.SlotNumber")];
  157. }
  158. if (!seqSlotWafers.ContainsKey(groupName))
  159. {
  160. seqSlotWafers[groupName] = new List<Tuple<ModuleName, int>>();
  161. }
  162. seqSlot[groupName][i] = true;
  163. if (!WaferManager.Instance.CheckHasWafer(module, i))
  164. {
  165. reason = $"job wafer: {module} slot {i + 1} not in the carrier";
  166. LOG.WriteLog(eEvent.WARN_ROUTER, ModuleName.System.ToString(), reason);
  167. return false;
  168. }
  169. if (!WaferManager.Instance.CheckWafer(ModuleHelper.Converter(module), i, WaferStatus.Normal))
  170. {
  171. reason = $"job wafer: {module} slot {i + 1} status is {WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).Status}";
  172. LOG.WriteLog(eEvent.WARN_ROUTER, ModuleName.System.ToString(), reason);
  173. return false;
  174. }
  175. WaferInfo waferInfo = WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i);
  176. if (waferInfo.Status != WaferStatus.Normal)
  177. {
  178. reason = $"job wafer: {module} slot {i + 1} status is {waferInfo.Status}";
  179. LOG.WriteLog(eEvent.WARN_ROUTER, ModuleName.System.ToString(), reason);
  180. return false;
  181. }
  182. if (waferInfo.ProcessState != EnumWaferProcessStatus.Idle)
  183. {
  184. reason = $"job wafer: {module} slot {i + 1} process status is {waferInfo.ProcessState}";
  185. LOG.WriteLog(eEvent.WARN_ROUTER, ModuleName.System.ToString(), reason);
  186. return false;
  187. }
  188. //--- 2024-03-21 增加了waferinfo 相应的lotId信息 start---
  189. cj.LotWafers.Add(waferInfo);
  190. waferInfo.SequenceName = slotSequence[i];
  191. waferInfo.LotId = lotId;
  192. //--- 2024-03-21 增加了waferinfo 相应的lotId信息 end---
  193. seqSlotWafers[groupName].Add(Tuple.Create(ModuleHelper.Converter(module), i));
  194. cj.JobWaferSize = WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).Size;
  195. waferCount++;
  196. LOG.WriteLog(eEvent.EV_ROUTER, ModuleName.System.ToString(), $"Assigned wafer job, wafer {module}.{i + 1}, sequence: {slotSequence[i]}");
  197. }
  198. if (seqSlotWafers.Count == 0)
  199. {
  200. reason = $"job has not assign wafer";
  201. LOG.WriteLog(eEvent.WARN_ROUTER, ModuleName.System.ToString(), reason);
  202. return false;
  203. }
  204. //AutoIdle
  205. if (Singleton<RouteManager>.Instance.IsAutoIdle)
  206. {
  207. bool waferCacheCheck = WaferManager.Instance.CheckStartUpCache(ref reason);
  208. if (!waferCacheCheck)
  209. {
  210. return true;
  211. }
  212. bool waferHolderCacheCheck = WaferHolderManager.Instance.CheckStartUpWaferHolderBuffer(ref reason);
  213. if (!waferHolderCacheCheck)
  214. {
  215. ClearWafersSeqName(cj);
  216. return false;
  217. }
  218. LoaderEntity loaderEntity = Singleton<RouteManager>.Instance.GetModule<LoaderEntity>(ModuleName.Loader1.ToString());
  219. if (loaderEntity != null && loaderEntity.WaferHolderInfo != null)
  220. {
  221. ClearWafersSeqName(cj);
  222. reason = "Loader Has WaferHolder";
  223. LOG.WriteLog(eEvent.WARN_ROUTER, ModuleName.System.ToString(), reason);
  224. return false;
  225. }
  226. UpdateAllBufferCellWaferHollderToLoader();
  227. }
  228. List<ProcessJobInfo> pjs = new List<ProcessJobInfo>();
  229. string[] seqs = seqSlot.Keys.ToArray();
  230. for (int i = 0; i < seqs.Length; i++)
  231. {
  232. ProcessJobInfo pj = new ProcessJobInfo();
  233. pj.Name = jobId + "_" + (i + 1);
  234. pj.ControlJobName = cj.Name;
  235. pj.LotName = lotId;
  236. pj.SlotWafers = seqSlotWafers[seqs[i]];
  237. pj.SetState(EnumProcessJobState.Queued);
  238. WaferSize slotWafersSize = GetWaferSize(pj.SlotWafers);
  239. string sequenceDirectory = sequenceType == PRODUCTION ? PathManager.GetProductionRecipeDir():PathManager.GetEngineeringRecipeDir();
  240. string recipeFullPath = sequenceDirectory + $"\\{indexSequence[seqs[i]]}.seq.rcp";
  241. SequenceRecipe sequenceRecipe = RecipeFileManager.Instance.LoadGenericityRecipe<SequenceRecipe>(recipeFullPath);
  242. if (sequenceRecipe==null)
  243. {
  244. reason = $"sequence recipe file {pj.Sequence} is not exist";
  245. LOG.WriteLog(eEvent.WARN_ROUTER, ModuleName.System.ToString(), reason);
  246. ClearWafersSeqName(cj);
  247. return false;
  248. }
  249. sequenceRecipe.SequenceType = sequenceType;
  250. if (!SchedulerSequenceRecipeManager.Instance.CheckSequenceRecipeAvaible(sequenceRecipe,ref reason))
  251. {
  252. ClearWafersSeqName(cj);
  253. return false;
  254. }
  255. if(!SchedulerSequenceRecipeManager.Instance.ExistAvaibleProcessCell(sequenceRecipe,true,true))
  256. {
  257. reason = "sequence meets no avaible cell";
  258. ClearWafersSeqName(cj);
  259. return false;
  260. }
  261. pj.SequenceRecipe= sequenceRecipe;
  262. WaferSize waferSize = (WaferSize)pj.SequenceRecipe.SubstrateSize;
  263. if (slotWafersSize!= waferSize)
  264. {
  265. reason = $"sequence wafersize {pj.SequenceRecipe.SubstrateSize} is not matched wafer wafersize {slotWafersSize}";
  266. LOG.WriteLog(eEvent.WARN_ROUTER, ModuleName.System.ToString(), reason);
  267. ClearWafersSeqName(cj);
  268. return false;
  269. }
  270. int sideAWaferSize = SC.GetValue<int>($"Loader1.SideAWaferSize");
  271. int sideBWaferSize = SC.GetValue<int>($"Loader1.SideBWaferSize");
  272. if ((int)waferSize != sideAWaferSize && (int)waferSize != sideBWaferSize)
  273. {
  274. reason = $"loader is not matched wafer wafersize {waferSize}";
  275. LOG.WriteLog(eEvent.WARN_ROUTER, ModuleName.System.ToString(), reason);
  276. ClearWafersSeqName(cj);
  277. return false;
  278. }
  279. int dummyCount = 0;
  280. DummyDevice dummy1Device = Singleton<RouteManager>.Instance.EFEM.GetDummyDevice(0);
  281. if(dummy1Device!=null&&dummy1Device.HasCassette&&dummy1Device.WaferSize==waferSize)
  282. {
  283. dummyCount++;
  284. }
  285. DummyDevice dummy2Device = Singleton<RouteManager>.Instance.EFEM.GetDummyDevice(1);
  286. if (dummy2Device != null && dummy2Device.HasCassette && dummy2Device.WaferSize == waferSize)
  287. {
  288. dummyCount++;
  289. }
  290. if (dummyCount == 0)
  291. {
  292. reason = $"dummy is not matched wafer wafersize {waferSize}";
  293. LOG.WriteLog(eEvent.WARN_ROUTER, ModuleName.System.ToString(), reason);
  294. ClearWafersSeqName(cj);
  295. return false;
  296. }
  297. string crsType = pj.SequenceRecipe.CrsType;
  298. List<string> chemistries = SchedulerSequenceRecipeManager.Instance.GetSequenceChemistry(pj.SequenceRecipe);
  299. if (ControlJobInfos.Count == 0)
  300. {
  301. bool avaibleWaferHolder= SchedulerManager.Instance.ExistAvaibleBufferWaferHolder(waferSize, crsType, chemistries);
  302. if (!avaibleWaferHolder)
  303. {
  304. reason = $"buffer has not enough wafer shuttle";
  305. LOG.WriteLog(eEvent.WARN_ROUTER, ModuleName.System.ToString(), reason);
  306. ClearWafersSeqName(cj);
  307. return false;
  308. }
  309. }
  310. else
  311. {
  312. int waferHolderCount = SchedulerManager.Instance.GetWaferHolderInfoCountByWaferSize(waferSize, crsType, chemistries);
  313. if (waferHolderCount == 0)
  314. {
  315. reason = $"buffer has not enough wafer shuttle";
  316. LOG.WriteLog(eEvent.WARN_ROUTER, ModuleName.System.ToString(), reason);
  317. ClearWafersSeqName(cj);
  318. return false;
  319. }
  320. }
  321. pjs.Add(pj);
  322. }
  323. _dbCallback.LotUpdate(cj);
  324. foreach (var pj in pjs)
  325. {
  326. cj.ProcessJobNameList.Add(pj.Name);
  327. _lstProcessJobs.Add(pj);
  328. }
  329. _lstControlJobs.Add(cj);
  330. //AssociatedPMWithLP(cj);
  331. _loadportControlJobDic[cj.Module] = cj;
  332. CycleManager.Instance.UpdateLoadportSp(cj.Module,cycleNumber);
  333. return true;
  334. }
  335. /// <summary>
  336. /// 获取Wafer尺寸
  337. /// </summary>
  338. /// <param name="slotWafers"></param>
  339. /// <returns></returns>
  340. private WaferSize GetWaferSize(List<Tuple<ModuleName,int>> slotWafers)
  341. {
  342. var result = slotWafers[0];
  343. WaferInfo waferInfo = WaferManager.Instance.GetWafer(result.Item1, result.Item2);
  344. if (!waferInfo.IsEmpty)
  345. {
  346. return waferInfo.Size;
  347. }
  348. return WaferSize.WS0;
  349. }
  350. /// <summary>
  351. /// 更新所有BufferCellWaferHolder可以拉至Loader
  352. /// </summary>
  353. private void UpdateAllBufferCellWaferHollderToLoader()
  354. {
  355. List<SchedulerModule> schedulerModules = SchedulerManager.Instance.GetModuleTypeScheduleModules(ModuleType.Buffer);
  356. foreach (SchedulerModule item in schedulerModules)
  357. {
  358. WaferHolderInfo waferHolderInfo = WaferHolderManager.Instance.GetWaferHolder(item.Module.ToString());
  359. if (waferHolderInfo != null)
  360. {
  361. waferHolderInfo.IsToLoader = true;
  362. }
  363. }
  364. }
  365. /// <summary>
  366. /// 增加processjob至字典中
  367. /// </summary>
  368. /// <param name="processJobInfo"></param>
  369. public void AddRecipeProcessJob(ProcessJobInfo processJobInfo)
  370. {
  371. List<ProcessJobInfo> jobs = null;
  372. if(_recipeProcessJobs.ContainsKey(processJobInfo.SequenceRecipe.Ppid))
  373. {
  374. jobs = _recipeProcessJobs[processJobInfo.SequenceRecipe.Ppid];
  375. }
  376. else
  377. {
  378. jobs = new List<ProcessJobInfo>();
  379. _recipeProcessJobs[processJobInfo.SequenceRecipe.Ppid]=jobs;
  380. }
  381. jobs.Add(processJobInfo);
  382. lock (_recipeLocker)
  383. {
  384. if(!_recipeList.Contains(processJobInfo.SequenceRecipe.Ppid))
  385. {
  386. _recipeList.Add(processJobInfo.SequenceRecipe.Ppid);
  387. }
  388. }
  389. }
  390. /// <summary>
  391. /// 获取启动recipe的Processjob集合
  392. /// </summary>
  393. /// <returns></returns>
  394. public List<ProcessJobInfo> GetRecipeStateProcessJobs(EnumProcessJobState enumProcessJobState)
  395. {
  396. bool isRunInParallelMode = SC.GetValue<Boolean>("Scheduler.IsRunInParallelMode");
  397. List<string> enableRecipeLst= new List<string>();
  398. lock (_recipeLocker)
  399. {
  400. if (_recipeList.Count != 0)
  401. {
  402. if (!isRunInParallelMode)
  403. {
  404. enableRecipeLst.Add(_recipeList[0]);
  405. }
  406. else
  407. {
  408. enableRecipeLst.AddRange(_recipeList);
  409. }
  410. }
  411. }
  412. List<ProcessJobInfo> processJobInfos = new List<ProcessJobInfo>();
  413. foreach (string recipe in enableRecipeLst)
  414. {
  415. if (!string.IsNullOrEmpty(recipe) && _recipeProcessJobs.ContainsKey(recipe))
  416. {
  417. List<ProcessJobInfo> recipeProcessJobs = _recipeProcessJobs[recipe];
  418. foreach (ProcessJobInfo processJobInfo in recipeProcessJobs)
  419. {
  420. if (processJobInfo.State == enumProcessJobState)
  421. {
  422. processJobInfos.Add(processJobInfo);
  423. }
  424. }
  425. }
  426. }
  427. return processJobInfos;
  428. }
  429. /// <summary>
  430. /// 移除recipe processjob字典中processjob
  431. /// </summary>
  432. /// <param name="processJobInfo"></param>
  433. public void RemoveRecipeProcessJob(ProcessJobInfo processJobInfo)
  434. {
  435. List<ProcessJobInfo> jobs = null;
  436. if (_recipeProcessJobs.ContainsKey(processJobInfo.SequenceRecipe.Ppid))
  437. {
  438. jobs = _recipeProcessJobs[processJobInfo.SequenceRecipe.Ppid];
  439. if(jobs.FindIndex(O => O.InnerId == processJobInfo.InnerId)>=0)
  440. {
  441. jobs.Remove(processJobInfo);
  442. }
  443. if (jobs.Count == 0)
  444. {
  445. _recipeProcessJobs.TryRemove(processJobInfo.SequenceRecipe.Ppid, out jobs);
  446. lock (_recipeLocker)
  447. {
  448. _recipeList.Remove(processJobInfo.SequenceRecipe.Ppid);
  449. }
  450. }
  451. }
  452. }
  453. /// <summary>
  454. /// 暂停Job
  455. /// </summary>
  456. /// <param name="jobName"></param>
  457. /// <param name="reason"></param>
  458. /// <returns></returns>
  459. public bool PauseJob(string jobName, out string reason)
  460. {
  461. reason = "";
  462. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  463. if (cj == null)
  464. {
  465. reason = $"pause job rejected, not found job with id {jobName}";
  466. return false;
  467. }
  468. if (cj.State == EnumControlJobState.Executing)
  469. {
  470. cj.SetState(EnumControlJobState.Paused);
  471. }
  472. _faCallback.JobPaused(cj);
  473. return true;
  474. }
  475. /// <summary>
  476. /// 恢复Job
  477. /// </summary>
  478. /// <param name="jobName"></param>
  479. /// <param name="reason"></param>
  480. /// <returns></returns>
  481. public bool ResumeJob(string jobName, out string reason)
  482. {
  483. reason = "";
  484. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  485. if (cj == null)
  486. {
  487. reason = $"resume job rejected, not found job with id {jobName}";
  488. //LOG.WriteLog(eEvent.WARN_ROUTER, ModuleName.System, $"resume job rejected, not found job with id {jobName}");
  489. return false;
  490. }
  491. if (cj.State == EnumControlJobState.Paused)
  492. {
  493. cj.SetState(EnumControlJobState.Executing);
  494. }
  495. _faCallback.JobResumed(cj);
  496. return true;
  497. }
  498. /// <summary>
  499. /// 启动任务
  500. /// </summary>
  501. /// <param name="jobName"></param>
  502. /// <param name="reason"></param>
  503. /// <returns></returns>
  504. public bool StartJob(string jobName, out string reason)
  505. {
  506. reason = "";
  507. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  508. if (cj == null)
  509. {
  510. reason = $"start job rejected, not found job with id {jobName}";
  511. LOG.WriteLog(eEvent.WARN_ROUTER, ModuleName.System.ToString(), reason);
  512. return false;
  513. }
  514. if (cj.State == EnumControlJobState.WaitingForStart)
  515. {
  516. cj.SetState(EnumControlJobState.Executing);
  517. cj.StartTime = DateTime.Now;
  518. _dbCallback.LotCreated(cj);
  519. _faCallback.JobStarted(cj);
  520. CycleManager.Instance.InitializeLoadPortData(cj.Module);
  521. foreach(string item in cj.ProcessJobNameList)
  522. {
  523. ProcessJobInfo pj=_lstProcessJobs.Find(O=>O.Name== item);
  524. if(pj !=null)
  525. {
  526. AddRecipeProcessJob(pj);
  527. }
  528. }
  529. }
  530. return true;
  531. }
  532. /// <summary>
  533. /// 停止任务
  534. /// </summary>
  535. /// <param name="jobName"></param>
  536. /// <param name="reason"></param>
  537. /// <returns></returns>
  538. public bool StopJob(string jobName, out string reason)
  539. {
  540. reason = "";
  541. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  542. if (cj == null)
  543. {
  544. reason = $"stop job rejected, not found job with id {jobName}";
  545. LOG.WriteLog(eEvent.WARN_ROUTER, ModuleName.System.ToString(), reason);
  546. return false;
  547. }
  548. if (cj.CycleNumber > 1)
  549. {
  550. cj.CycleNumber = 1;
  551. LOG.WriteLog(eEvent.WARN_ROUTER, ModuleName.System.ToString(), $"stop controljob {cj.Name} cycle number changed to 1");
  552. }
  553. int processJobCount = 0;
  554. foreach (var pj in _lstProcessJobs)
  555. {
  556. if (pj.ControlJobName == cj.Name)
  557. {
  558. pj.SetState(EnumProcessJobState.Stopping);
  559. int count = 0;
  560. foreach (var pjSlotWafer in pj.SlotWafers)
  561. {
  562. if (WaferManager.Instance.CheckHasWafer(pjSlotWafer.Item1, pjSlotWafer.Item2))
  563. {
  564. WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  565. if (WaferTaskManager.Instance.Contains(wafer.WaferID))
  566. {
  567. continue;
  568. }
  569. if (wafer.ProcessState == EnumWaferProcessStatus.Idle)
  570. {
  571. wafer.ProcessState = EnumWaferProcessStatus.Canceled;
  572. count++;
  573. LOG.WriteLog(eEvent.EV_SCHEDULER, "System", $"{pjSlotWafer.Item1}.{pjSlotWafer.Item2} cancel process");
  574. }
  575. }
  576. }
  577. if (count == pj.SlotWafers.Count)
  578. {
  579. processJobCount++;
  580. }
  581. }
  582. }
  583. if (processJobCount == _lstProcessJobs.Count)
  584. {
  585. List<ProcessJobInfo> lst = _lstProcessJobs.ToList();
  586. foreach (var pj in lst)
  587. {
  588. _lstProcessJobs.Remove(pj);
  589. RemoveRecipeProcessJob(pj);
  590. LOG.WriteLog(eEvent.EV_SCHEDULER, "System", $"controljob {cj.Name} processjob {pj.SequenceRecipe.Ppid} removed");
  591. }
  592. }
  593. if (processJobCount == _lstProcessJobs.Count)
  594. {
  595. ClearLoadPortControlJob(cj);
  596. _lstControlJobs.Remove(cj);
  597. _faCallback.JobStopped(cj);
  598. _dbCallback.LotFinished(cj);
  599. LOG.WriteLog(eEvent.EV_SCHEDULER, "System", $"controljob {cj.Name} removed");
  600. }
  601. return true;
  602. }
  603. /// <summary>
  604. /// 获取正在执行的ControlJob
  605. /// </summary>
  606. /// <returns></returns>
  607. public ControlJobInfo GetRunningControlJob()
  608. {
  609. return _lstControlJobs.Find(O => O.State == EnumControlJobState.Executing);
  610. }
  611. /// <summary>
  612. /// 获取正在执行的ControlJob集合
  613. /// </summary>
  614. /// <returns></returns>
  615. public List<ControlJobInfo> getRunningControlJobs()
  616. {
  617. return _lstControlJobs.FindAll(O => O.State == EnumControlJobState.Executing);
  618. }
  619. /// <summary>
  620. /// ControlJob任务完成
  621. /// </summary>
  622. public void CompleteControlJob(ControlJobInfo controlJobInfo)
  623. {
  624. controlJobInfo.SetState(EnumControlJobState.Completed);
  625. controlJobInfo.EndTime = DateTime.Now;
  626. _dbCallback.LotFinished(controlJobInfo);
  627. _faCallback.JobFinished(controlJobInfo);
  628. List<ProcessJobInfo> pjRemoveList = new List<ProcessJobInfo>();
  629. foreach (var pj in _lstProcessJobs)
  630. {
  631. if (pj.ControlJobName == controlJobInfo.Name)
  632. pjRemoveList.Add(pj);
  633. }
  634. foreach (var pj in pjRemoveList)
  635. {
  636. _lstProcessJobs.Remove(pj);
  637. RemoveRecipeProcessJob(pj);
  638. }
  639. ClearLoadPortControlJob(controlJobInfo);
  640. _lstControlJobs.Remove(controlJobInfo);
  641. }
  642. /// <summary>
  643. /// 清除LoadPort ControlJob
  644. /// </summary>
  645. /// <param name="controlJobInfo"></param>
  646. private void ClearLoadPortControlJob(ControlJobInfo controlJobInfo)
  647. {
  648. string[] keys = _loadportControlJobDic.Keys.ToArray();
  649. foreach(string key in keys)
  650. {
  651. ControlJobInfo tmp= _loadportControlJobDic[key];
  652. if(tmp!=null&&tmp.Name==controlJobInfo.Name)
  653. {
  654. _loadportControlJobDic[key] = null;
  655. }
  656. }
  657. }
  658. /// <summary>
  659. /// 重新启动任务
  660. /// </summary>
  661. /// <param name="controlJobInfo"></param>
  662. public void RestartControlJob(ControlJobInfo controlJobInfo)
  663. {
  664. List<ProcessJobInfo> pjRemoveList = new List<ProcessJobInfo>();
  665. foreach (var pj in _lstProcessJobs)
  666. {
  667. if (pj.ControlJobName == controlJobInfo.Name)
  668. pjRemoveList.Add(pj);
  669. }
  670. foreach (var pj in pjRemoveList)
  671. {
  672. RemoveRecipeProcessJob(pj);
  673. }
  674. pjRemoveList.Clear();
  675. controlJobInfo.SetState(EnumControlJobState.Executing);
  676. controlJobInfo.InnerId= Guid.NewGuid();
  677. controlJobInfo.LotInnerId= Guid.NewGuid();
  678. _dbCallback.LotCreated(controlJobInfo);
  679. foreach (var pj in _lstProcessJobs)
  680. {
  681. if (pj.ControlJobName == controlJobInfo.Name)
  682. {
  683. pj.SetState(EnumProcessJobState.Queued);
  684. pj.InnerId = Guid.NewGuid();
  685. foreach (var pjSlotWafer in pj.SlotWafers)
  686. {
  687. WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  688. wafer.ProcessJob = null;
  689. wafer.NextSequenceStep = 0;
  690. wafer.ProcessState = EnumWaferProcessStatus.Idle;
  691. }
  692. AddRecipeProcessJob(pj);
  693. }
  694. }
  695. }
  696. /// <summary>
  697. /// 获取Job对象
  698. /// </summary>
  699. /// <param name="name"></param>
  700. /// <returns></returns>
  701. public ControlJobInfo GetControlJobInfoByName(string name)
  702. {
  703. return _lstControlJobs.Find(O=>O.Name == name);
  704. }
  705. /// <summary>
  706. /// 根据ProcessJob获取ControlJob
  707. /// </summary>
  708. /// <param name="processJobInfo"></param>
  709. /// <returns></returns>
  710. public ControlJobInfo GetControlJobInfoByProcessJob(ProcessJobInfo processJobInfo)
  711. {
  712. return _lstControlJobs.Find(O => O.Name == processJobInfo.ControlJobName);
  713. }
  714. /// <summary>
  715. /// System Abort
  716. /// </summary>
  717. public void SystemAbort()
  718. {
  719. List<ControlJobInfo> controlJobInfos = _lstControlJobs.ToList();
  720. foreach(var item in controlJobInfos)
  721. {
  722. StopJob(item.Name, out string reason);
  723. }
  724. }
  725. /// <summary>
  726. /// 移除所有job
  727. /// </summary>
  728. public void RemoveAllJob()
  729. {
  730. List<ControlJobInfo> controlJobInfos = _lstControlJobs.ToList();
  731. foreach (var item in controlJobInfos)
  732. {
  733. List<ProcessJobInfo> pjRemoveList = new List<ProcessJobInfo>();
  734. foreach (var pj in _lstProcessJobs)
  735. {
  736. if (pj.ControlJobName == item.Name)
  737. pjRemoveList.Add(pj);
  738. }
  739. foreach (var pj in pjRemoveList)
  740. {
  741. _lstProcessJobs.Remove(pj);
  742. RemoveRecipeProcessJob(pj);
  743. }
  744. ClearLoadPortControlJob(item);
  745. _lstControlJobs.Remove(item);
  746. }
  747. WaferTaskManager.Instance.RemoveAllTask();
  748. WaferHolderTaskManager.Instance.RemoveAllTask();
  749. SchedulerManager.Instance.ResetSchedulerModule();
  750. }
  751. /// <summary>
  752. /// 获取loadport的controljob
  753. /// </summary>
  754. /// <param name="loadPort"></param>
  755. /// <returns></returns>
  756. public ControlJobInfo GetControlJobInfoByLoadPort(string loadPort)
  757. {
  758. return _loadportControlJobDic.ContainsKey(loadPort)?_loadportControlJobDic[loadPort]:null;
  759. }
  760. /// <summary>
  761. /// 清除WaferSeqName信息
  762. /// </summary>
  763. private void ClearWafersSeqName(ControlJobInfo cj)
  764. {
  765. foreach (var item in cj.LotWafers)
  766. {
  767. item.SequenceName = "";
  768. }
  769. }
  770. }
  771. }