JobProcesser.cs 32 KB

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