JobProcesser.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  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. if (WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).ProcessState != EnumWaferProcessStatus.Idle)
  176. {
  177. reason = $"job wafer: {module} slot {i + 1} process status is {WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).ProcessState}";
  178. LOG.WriteLog(eEvent.WARN_ROUTER, ModuleName.System.ToString(), reason);
  179. return false;
  180. }
  181. //--- 2024-03-21 增加了waferinfo 相应的lotId信息 start---
  182. WaferInfo waferInfo = WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i);
  183. cj.LotWafers.Add(waferInfo);
  184. waferInfo.SequenceName = slotSequence[i];
  185. waferInfo.LotId = lotId;
  186. //--- 2024-03-21 增加了waferinfo 相应的lotId信息 end---
  187. seqSlotWafers[groupName].Add(Tuple.Create(ModuleHelper.Converter(module), i));
  188. cj.JobWaferSize = WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).Size;
  189. waferCount++;
  190. LOG.WriteLog(eEvent.EV_ROUTER, ModuleName.System.ToString(), $"Assigned wafer job, wafer {module}.{i + 1}, sequence: {slotSequence[i]}");
  191. }
  192. if (seqSlotWafers.Count == 0)
  193. {
  194. reason = $"job has not assign wafer";
  195. LOG.WriteLog(eEvent.WARN_ROUTER, ModuleName.System.ToString(), reason);
  196. return false;
  197. }
  198. //AutoIdle
  199. if (Singleton<RouteManager>.Instance.IsAutoIdle)
  200. {
  201. bool waferCacheCheck = WaferManager.Instance.CheckStartUpCache(ref reason);
  202. if (!waferCacheCheck)
  203. {
  204. return true;
  205. }
  206. bool waferHolderCacheCheck = WaferHolderManager.Instance.CheckStartUpWaferHolderBuffer(ref reason);
  207. if (!waferHolderCacheCheck)
  208. {
  209. return false;
  210. }
  211. LoaderEntity loaderEntity = Singleton<RouteManager>.Instance.GetModule<LoaderEntity>(ModuleName.Loader1.ToString());
  212. if (loaderEntity != null && loaderEntity.WaferHolderInfo != null)
  213. {
  214. reason = "Loader Has WaferHolder";
  215. LOG.WriteLog(eEvent.WARN_ROUTER, ModuleName.System.ToString(), reason);
  216. return false;
  217. }
  218. UpdateAllBufferCellWaferHollderToLoader();
  219. }
  220. List<ProcessJobInfo> pjs = new List<ProcessJobInfo>();
  221. string[] seqs = seqSlot.Keys.ToArray();
  222. for (int i = 0; i < seqs.Length; i++)
  223. {
  224. ProcessJobInfo pj = new ProcessJobInfo();
  225. pj.Name = jobId + "_" + (i + 1);
  226. pj.ControlJobName = cj.Name;
  227. pj.LotName = lotId;
  228. pj.SlotWafers = seqSlotWafers[seqs[i]];
  229. pj.SetState(EnumProcessJobState.Queued);
  230. WaferSize slotWafersSize = GetWaferSize(pj.SlotWafers);
  231. string sequenceDirectory = sequenceType == PRODUCTION ? PathManager.GetProductionRecipeDir():PathManager.GetEngineeringRecipeDir();
  232. string recipeFullPath = sequenceDirectory + $"\\{indexSequence[seqs[i]]}.seq.rcp";
  233. SequenceRecipe sequenceRecipe = RecipeFileManager.Instance.LoadGenericityRecipe<SequenceRecipe>(recipeFullPath);
  234. if (sequenceRecipe==null)
  235. {
  236. reason = $"sequence recipe file {pj.Sequence} is not exist";
  237. LOG.WriteLog(eEvent.WARN_ROUTER, ModuleName.System.ToString(), reason);
  238. return false;
  239. }
  240. sequenceRecipe.SequenceType = sequenceType;
  241. if (!SchedulerSequenceRecipeManager.Instance.CheckSequenceRecipeAvaible(sequenceRecipe,ref reason))
  242. {
  243. return false;
  244. }
  245. if(!SchedulerSequenceRecipeManager.Instance.ExistAvaibleProcessCell(sequenceRecipe,true,true))
  246. {
  247. reason = "sequence meets no avaible cell";
  248. return false;
  249. }
  250. pj.SequenceRecipe= sequenceRecipe;
  251. WaferSize waferSize = (WaferSize)pj.SequenceRecipe.SubstrateSize;
  252. if (slotWafersSize!= waferSize)
  253. {
  254. reason = $"sequence wafersize {pj.SequenceRecipe.SubstrateSize} is not matched wafer wafersize {slotWafersSize}";
  255. LOG.WriteLog(eEvent.WARN_ROUTER, ModuleName.System.ToString(), reason);
  256. return false;
  257. }
  258. int sideAWaferSize = SC.GetValue<int>($"Loader1.SideAWaferSize");
  259. int sideBWaferSize = SC.GetValue<int>($"Loader1.SideBWaferSize");
  260. if ((int)waferSize != sideAWaferSize && (int)waferSize != sideBWaferSize)
  261. {
  262. reason = $"loader is not matched wafer wafersize {waferSize}";
  263. LOG.WriteLog(eEvent.WARN_ROUTER, ModuleName.System.ToString(), reason);
  264. return false;
  265. }
  266. int dummyCount = 0;
  267. DummyDevice dummy1Device = Singleton<RouteManager>.Instance.EFEM.GetDummyDevice(0);
  268. if(dummy1Device!=null&&dummy1Device.HasCassette&&dummy1Device.WaferSize==waferSize)
  269. {
  270. dummyCount++;
  271. }
  272. DummyDevice dummy2Device = Singleton<RouteManager>.Instance.EFEM.GetDummyDevice(1);
  273. if (dummy2Device != null && dummy2Device.HasCassette && dummy2Device.WaferSize == waferSize)
  274. {
  275. dummyCount++;
  276. }
  277. if (dummyCount == 0)
  278. {
  279. reason = $"dummy is not matched wafer wafersize {waferSize}";
  280. LOG.WriteLog(eEvent.WARN_ROUTER, ModuleName.System.ToString(), reason);
  281. return false;
  282. }
  283. string crsType = pj.SequenceRecipe.CrsType;
  284. List<string> chemistries = SchedulerSequenceRecipeManager.Instance.GetSequenceChemistry(pj.SequenceRecipe);
  285. if (ControlJobInfos.Count == 0)
  286. {
  287. bool avaibleWaferHolder= SchedulerManager.Instance.ExistAvaibleBufferWaferHolder(waferSize, crsType, chemistries);
  288. if (!avaibleWaferHolder)
  289. {
  290. reason = $"buffer has not enough wafer shuttle";
  291. LOG.WriteLog(eEvent.WARN_ROUTER, ModuleName.System.ToString(), reason);
  292. return false;
  293. }
  294. }
  295. else
  296. {
  297. int waferHolderCount = SchedulerManager.Instance.GetWaferHolderInfoCountByWaferSize(waferSize, crsType, chemistries);
  298. if (waferHolderCount == 0)
  299. {
  300. reason = $"buffer has not enough wafer shuttle";
  301. LOG.WriteLog(eEvent.WARN_ROUTER, ModuleName.System.ToString(), reason);
  302. return false;
  303. }
  304. }
  305. pjs.Add(pj);
  306. }
  307. _dbCallback.LotUpdate(cj);
  308. foreach (var pj in pjs)
  309. {
  310. cj.ProcessJobNameList.Add(pj.Name);
  311. _lstProcessJobs.Add(pj);
  312. }
  313. _lstControlJobs.Add(cj);
  314. //AssociatedPMWithLP(cj);
  315. _loadportControlJobDic[cj.Module] = cj;
  316. CycleManager.Instance.UpdateLoadportSp(cj.Module,cycleNumber);
  317. return true;
  318. }
  319. /// <summary>
  320. /// 获取Wafer尺寸
  321. /// </summary>
  322. /// <param name="slotWafers"></param>
  323. /// <returns></returns>
  324. private WaferSize GetWaferSize(List<Tuple<ModuleName,int>> slotWafers)
  325. {
  326. var result = slotWafers[0];
  327. WaferInfo waferInfo = WaferManager.Instance.GetWafer(result.Item1, result.Item2);
  328. if (!waferInfo.IsEmpty)
  329. {
  330. return waferInfo.Size;
  331. }
  332. return WaferSize.WS0;
  333. }
  334. /// <summary>
  335. /// 更新所有BufferCellWaferHolder可以拉至Loader
  336. /// </summary>
  337. private void UpdateAllBufferCellWaferHollderToLoader()
  338. {
  339. List<SchedulerModule> schedulerModules = SchedulerManager.Instance.GetModuleTypeScheduleModules(ModuleType.Buffer);
  340. foreach (SchedulerModule item in schedulerModules)
  341. {
  342. WaferHolderInfo waferHolderInfo = WaferHolderManager.Instance.GetWaferHolder(item.Module.ToString());
  343. if (waferHolderInfo != null)
  344. {
  345. waferHolderInfo.IsToLoader = true;
  346. }
  347. }
  348. }
  349. /// <summary>
  350. /// 增加processjob至字典中
  351. /// </summary>
  352. /// <param name="processJobInfo"></param>
  353. public void AddRecipeProcessJob(ProcessJobInfo processJobInfo)
  354. {
  355. List<ProcessJobInfo> jobs = null;
  356. if(_recipeProcessJobs.ContainsKey(processJobInfo.SequenceRecipe.Ppid))
  357. {
  358. jobs = _recipeProcessJobs[processJobInfo.SequenceRecipe.Ppid];
  359. }
  360. else
  361. {
  362. jobs = new List<ProcessJobInfo>();
  363. _recipeProcessJobs[processJobInfo.SequenceRecipe.Ppid]=jobs;
  364. }
  365. jobs.Add(processJobInfo);
  366. lock (_recipeLocker)
  367. {
  368. if(!_recipeList.Contains(processJobInfo.SequenceRecipe.Ppid))
  369. {
  370. _recipeList.Add(processJobInfo.SequenceRecipe.Ppid);
  371. }
  372. }
  373. }
  374. /// <summary>
  375. /// 获取启动recipe的Processjob集合
  376. /// </summary>
  377. /// <returns></returns>
  378. public List<ProcessJobInfo> GetRecipeStateProcessJobs(EnumProcessJobState enumProcessJobState)
  379. {
  380. string recipe = "";
  381. lock (_recipeLocker)
  382. {
  383. if (_recipeList.Count != 0)
  384. {
  385. recipe = _recipeList[0];
  386. }
  387. }
  388. List<ProcessJobInfo> processJobInfos = new List<ProcessJobInfo>();
  389. if(!string.IsNullOrEmpty(recipe)&&_recipeProcessJobs.ContainsKey(recipe))
  390. {
  391. List<ProcessJobInfo> recipeProcessJobs = _recipeProcessJobs[recipe];
  392. foreach (ProcessJobInfo processJobInfo in recipeProcessJobs)
  393. {
  394. if (processJobInfo.State == enumProcessJobState)
  395. {
  396. processJobInfos.Add(processJobInfo);
  397. }
  398. }
  399. }
  400. return processJobInfos;
  401. }
  402. /// <summary>
  403. /// 移除recipe processjob字典中processjob
  404. /// </summary>
  405. /// <param name="processJobInfo"></param>
  406. private void RemoveRecipeProcessJob(ProcessJobInfo processJobInfo)
  407. {
  408. List<ProcessJobInfo> jobs = null;
  409. if (_recipeProcessJobs.ContainsKey(processJobInfo.SequenceRecipe.Ppid))
  410. {
  411. jobs = _recipeProcessJobs[processJobInfo.SequenceRecipe.Ppid];
  412. if(jobs.FindIndex(O => O.InnerId == processJobInfo.InnerId)>=0)
  413. {
  414. jobs.Remove(processJobInfo);
  415. }
  416. if (jobs.Count == 0)
  417. {
  418. _recipeProcessJobs.TryRemove(processJobInfo.SequenceRecipe.Ppid, out jobs);
  419. lock (_recipeLocker)
  420. {
  421. _recipeList.Remove(processJobInfo.SequenceRecipe.Ppid);
  422. }
  423. }
  424. }
  425. }
  426. /// <summary>
  427. /// 暂停Job
  428. /// </summary>
  429. /// <param name="jobName"></param>
  430. /// <param name="reason"></param>
  431. /// <returns></returns>
  432. public bool PauseJob(string jobName, out string reason)
  433. {
  434. reason = "";
  435. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  436. if (cj == null)
  437. {
  438. reason = $"pause job rejected, not found job with id {jobName}";
  439. return false;
  440. }
  441. if (cj.State == EnumControlJobState.Executing)
  442. {
  443. cj.SetState(EnumControlJobState.Paused);
  444. }
  445. _faCallback.JobPaused(cj);
  446. return true;
  447. }
  448. /// <summary>
  449. /// 恢复Job
  450. /// </summary>
  451. /// <param name="jobName"></param>
  452. /// <param name="reason"></param>
  453. /// <returns></returns>
  454. public bool ResumeJob(string jobName, out string reason)
  455. {
  456. reason = "";
  457. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  458. if (cj == null)
  459. {
  460. reason = $"resume job rejected, not found job with id {jobName}";
  461. //LOG.WriteLog(eEvent.WARN_ROUTER, ModuleName.System, $"resume job rejected, not found job with id {jobName}");
  462. return false;
  463. }
  464. if (cj.State == EnumControlJobState.Paused)
  465. {
  466. cj.SetState(EnumControlJobState.Executing);
  467. }
  468. _faCallback.JobResumed(cj);
  469. return true;
  470. }
  471. /// <summary>
  472. /// 启动任务
  473. /// </summary>
  474. /// <param name="jobName"></param>
  475. /// <param name="reason"></param>
  476. /// <returns></returns>
  477. public bool StartJob(string jobName, out string reason)
  478. {
  479. reason = "";
  480. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  481. if (cj == null)
  482. {
  483. reason = $"start job rejected, not found job with id {jobName}";
  484. LOG.WriteLog(eEvent.WARN_ROUTER, ModuleName.System.ToString(), reason);
  485. return false;
  486. }
  487. if (cj.State == EnumControlJobState.WaitingForStart)
  488. {
  489. cj.SetState(EnumControlJobState.Executing);
  490. cj.StartTime = DateTime.Now;
  491. _dbCallback.LotCreated(cj);
  492. _faCallback.JobStarted(cj);
  493. CycleManager.Instance.InitializeLoadPortData(cj.Module);
  494. foreach(string item in cj.ProcessJobNameList)
  495. {
  496. ProcessJobInfo pj=_lstProcessJobs.Find(O=>O.Name== item);
  497. if(pj !=null)
  498. {
  499. AddRecipeProcessJob(pj);
  500. }
  501. }
  502. }
  503. return true;
  504. }
  505. /// <summary>
  506. /// 停止任务
  507. /// </summary>
  508. /// <param name="jobName"></param>
  509. /// <param name="reason"></param>
  510. /// <returns></returns>
  511. public bool StopJob(string jobName, out string reason)
  512. {
  513. reason = "";
  514. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  515. if (cj == null)
  516. {
  517. reason = $"stop job rejected, not found job with id {jobName}";
  518. LOG.WriteLog(eEvent.WARN_ROUTER, ModuleName.System.ToString(), reason);
  519. return false;
  520. }
  521. if (cj.CycleNumber > 1)
  522. {
  523. cj.CycleNumber = 1;
  524. LOG.WriteLog(eEvent.WARN_ROUTER, ModuleName.System.ToString(), $"stop controljob {cj.Name} cycle number changed to 1");
  525. }
  526. int processJobCount = 0;
  527. foreach (var pj in _lstProcessJobs)
  528. {
  529. if (pj.ControlJobName == cj.Name)
  530. {
  531. pj.SetState(EnumProcessJobState.Stopping);
  532. int count = 0;
  533. foreach (var pjSlotWafer in pj.SlotWafers)
  534. {
  535. if (WaferManager.Instance.CheckHasWafer(pjSlotWafer.Item1, pjSlotWafer.Item2))
  536. {
  537. WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  538. if (WaferTaskManager.Instance.Contains(wafer.WaferID))
  539. {
  540. continue;
  541. }
  542. if (wafer.ProcessState == EnumWaferProcessStatus.Idle)
  543. {
  544. wafer.ProcessState = EnumWaferProcessStatus.Canceled;
  545. count++;
  546. LOG.WriteLog(eEvent.EV_SCHEDULER, "System", $"{pjSlotWafer.Item1}.{pjSlotWafer.Item2} cancel process");
  547. }
  548. }
  549. }
  550. if (count == pj.SlotWafers.Count)
  551. {
  552. processJobCount++;
  553. }
  554. }
  555. }
  556. if (processJobCount == _lstProcessJobs.Count)
  557. {
  558. List<ProcessJobInfo> lst = _lstProcessJobs.ToList();
  559. foreach (var pj in lst)
  560. {
  561. _lstProcessJobs.Remove(pj);
  562. RemoveRecipeProcessJob(pj);
  563. LOG.WriteLog(eEvent.EV_SCHEDULER, "System", $"controljob {cj.Name} processjob {pj.SequenceRecipe.Ppid} removed");
  564. }
  565. }
  566. if (processJobCount == _lstProcessJobs.Count)
  567. {
  568. ClearLoadPortControlJob(cj);
  569. _lstControlJobs.Remove(cj);
  570. _faCallback.JobStopped(cj);
  571. _dbCallback.LotFinished(cj);
  572. LOG.WriteLog(eEvent.EV_SCHEDULER, "System", $"controljob {cj.Name} removed");
  573. }
  574. return true;
  575. }
  576. /// <summary>
  577. /// 获取正在执行的ControlJob
  578. /// </summary>
  579. /// <returns></returns>
  580. public ControlJobInfo GetRunningControlJob()
  581. {
  582. return _lstControlJobs.Find(O => O.State == EnumControlJobState.Executing);
  583. }
  584. /// <summary>
  585. /// 获取正在执行的ControlJob集合
  586. /// </summary>
  587. /// <returns></returns>
  588. public List<ControlJobInfo> getRunningControlJobs()
  589. {
  590. return _lstControlJobs.FindAll(O => O.State == EnumControlJobState.Executing);
  591. }
  592. /// <summary>
  593. /// ControlJob任务完成
  594. /// </summary>
  595. public void CompleteControlJob(ControlJobInfo controlJobInfo)
  596. {
  597. controlJobInfo.SetState(EnumControlJobState.Completed);
  598. controlJobInfo.EndTime = DateTime.Now;
  599. _dbCallback.LotFinished(controlJobInfo);
  600. _faCallback.JobFinished(controlJobInfo);
  601. List<ProcessJobInfo> pjRemoveList = new List<ProcessJobInfo>();
  602. foreach (var pj in _lstProcessJobs)
  603. {
  604. if (pj.ControlJobName == controlJobInfo.Name)
  605. pjRemoveList.Add(pj);
  606. }
  607. foreach (var pj in pjRemoveList)
  608. {
  609. _lstProcessJobs.Remove(pj);
  610. RemoveRecipeProcessJob(pj);
  611. }
  612. ClearLoadPortControlJob(controlJobInfo);
  613. _lstControlJobs.Remove(controlJobInfo);
  614. }
  615. /// <summary>
  616. /// 清除LoadPort ControlJob
  617. /// </summary>
  618. /// <param name="controlJobInfo"></param>
  619. private void ClearLoadPortControlJob(ControlJobInfo controlJobInfo)
  620. {
  621. string[] keys = _loadportControlJobDic.Keys.ToArray();
  622. foreach(string key in keys)
  623. {
  624. ControlJobInfo tmp= _loadportControlJobDic[key];
  625. if(tmp!=null&&tmp.Name==controlJobInfo.Name)
  626. {
  627. _loadportControlJobDic[key] = null;
  628. }
  629. }
  630. }
  631. /// <summary>
  632. /// 重新启动任务
  633. /// </summary>
  634. /// <param name="controlJobInfo"></param>
  635. public void RestartControlJob(ControlJobInfo controlJobInfo)
  636. {
  637. List<ProcessJobInfo> pjRemoveList = new List<ProcessJobInfo>();
  638. foreach (var pj in _lstProcessJobs)
  639. {
  640. if (pj.ControlJobName == controlJobInfo.Name)
  641. pjRemoveList.Add(pj);
  642. }
  643. foreach (var pj in pjRemoveList)
  644. {
  645. RemoveRecipeProcessJob(pj);
  646. }
  647. pjRemoveList.Clear();
  648. controlJobInfo.SetState(EnumControlJobState.Executing);
  649. controlJobInfo.InnerId= Guid.NewGuid();
  650. controlJobInfo.LotInnerId= Guid.NewGuid();
  651. _dbCallback.LotCreated(controlJobInfo);
  652. foreach (var pj in _lstProcessJobs)
  653. {
  654. if (pj.ControlJobName == controlJobInfo.Name)
  655. {
  656. pj.SetState(EnumProcessJobState.Queued);
  657. pj.InnerId = Guid.NewGuid();
  658. foreach (var pjSlotWafer in pj.SlotWafers)
  659. {
  660. WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  661. wafer.ProcessJob = null;
  662. wafer.NextSequenceStep = 0;
  663. wafer.ProcessState = EnumWaferProcessStatus.Idle;
  664. }
  665. AddRecipeProcessJob(pj);
  666. }
  667. }
  668. }
  669. /// <summary>
  670. /// 获取Job对象
  671. /// </summary>
  672. /// <param name="name"></param>
  673. /// <returns></returns>
  674. public ControlJobInfo GetControlJobInfoByName(string name)
  675. {
  676. return _lstControlJobs.Find(O=>O.Name == name);
  677. }
  678. /// <summary>
  679. /// 根据ProcessJob获取ControlJob
  680. /// </summary>
  681. /// <param name="processJobInfo"></param>
  682. /// <returns></returns>
  683. public ControlJobInfo GetControlJobInfoByProcessJob(ProcessJobInfo processJobInfo)
  684. {
  685. return _lstControlJobs.Find(O => O.Name == processJobInfo.ControlJobName);
  686. }
  687. /// <summary>
  688. /// System Abort
  689. /// </summary>
  690. public void SystemAbort()
  691. {
  692. List<ControlJobInfo> controlJobInfos = _lstControlJobs.ToList();
  693. foreach(var item in controlJobInfos)
  694. {
  695. StopJob(item.Name, out string reason);
  696. }
  697. }
  698. /// <summary>
  699. /// 移除所有job
  700. /// </summary>
  701. public void RemoveAllJob()
  702. {
  703. List<ControlJobInfo> controlJobInfos = _lstControlJobs.ToList();
  704. foreach (var item in controlJobInfos)
  705. {
  706. List<ProcessJobInfo> pjRemoveList = new List<ProcessJobInfo>();
  707. foreach (var pj in _lstProcessJobs)
  708. {
  709. if (pj.ControlJobName == item.Name)
  710. pjRemoveList.Add(pj);
  711. }
  712. foreach (var pj in pjRemoveList)
  713. {
  714. _lstProcessJobs.Remove(pj);
  715. RemoveRecipeProcessJob(pj);
  716. }
  717. ClearLoadPortControlJob(item);
  718. _lstControlJobs.Remove(item);
  719. }
  720. WaferTaskManager.Instance.RemoveAllTask();
  721. WaferHolderTaskManager.Instance.RemoveAllTask();
  722. SchedulerManager.Instance.ResetSchedulerModule();
  723. }
  724. /// <summary>
  725. /// 获取loadport的controljob
  726. /// </summary>
  727. /// <param name="loadPort"></param>
  728. /// <returns></returns>
  729. public ControlJobInfo GetControlJobInfoByLoadPort(string loadPort)
  730. {
  731. return _loadportControlJobDic.ContainsKey(loadPort)?_loadportControlJobDic[loadPort]:null;
  732. }
  733. }
  734. }