markus / ConvertService / ServiceBase / Markus.Service.Station / StationService / ServiceStationTask.cs @ a5e5fff6
이력 | 보기 | 이력해설 | 다운로드 (21.8 KB)
1 | a5e5fff6 | taeseongkim | using Markus.Message; |
---|---|---|---|
2 | 53c9637d | taeseongkim | using System; |
3 | using System.Collections.Generic; |
||
4 | using System.Diagnostics; |
||
5 | using System.Linq; |
||
6 | using System.Text; |
||
7 | using System.Threading; |
||
8 | using System.Threading.Tasks; |
||
9 | using System.Management; |
||
10 | using static Markus.Service.Extensions.Encrypt; |
||
11 | using Markus.Service.Extensions; |
||
12 | using Markus.Service.Helper; |
||
13 | a5e5fff6 | taeseongkim | using Markus.Service.DataBase.Entities; |
14 | using Markus.Service.DataBase.Repositories; |
||
15 | 53c9637d | taeseongkim | |
16 | namespace Markus.Service |
||
17 | { |
||
18 | /// <summary> |
||
19 | /// 컨버터 큐 처리 |
||
20 | /// </summary> |
||
21 | public partial class ServiceStation |
||
22 | { |
||
23 | /// <summary> |
||
24 | /// 컨버터 실행중인 item |
||
25 | /// </summary> |
||
26 | a5e5fff6 | taeseongkim | private static List<ConvertDoc> AliveConvertQueue = new List<ConvertDoc>(); |
27 | 53c9637d | taeseongkim | |
28 | /// <summary> |
||
29 | /// 컨버터 프로세스 실행 |
||
30 | /// </summary> |
||
31 | /// <param name="convertitem"></param> |
||
32 | a5e5fff6 | taeseongkim | public bool ConvertProcessStart(ConvertDoc convertitem) |
33 | 53c9637d | taeseongkim | { |
34 | bool result = false; |
||
35 | try |
||
36 | { |
||
37 | |||
38 | Process ConvertProcess = new Process(); |
||
39 | |||
40 | ProcessContext processSendData = new ProcessContext |
||
41 | { |
||
42 | a5e5fff6 | taeseongkim | ConvertID = convertitem.ID, |
43 | 53c9637d | taeseongkim | ConnectionString = MarkusDBConnectionString, |
44 | ServiceStationUri = gServiceHostAddress.ToString(), |
||
45 | a5e5fff6 | taeseongkim | OriginFilePath = convertitem.DOCUMENT_URL, |
46 | 53c9637d | taeseongkim | SaveDirectory = convertitem.ConvertPath, |
47 | TempDirectory = DownloadTempFolder, |
||
48 | 8feb21df | taeseongkim | ReleaseWorkMemory = ReleaseWorkMemory, |
49 | 53c9637d | taeseongkim | MultiThreadMaxPages = MultiThreadMaxPages, |
50 | MinFontSize = MinFontSize, |
||
51 | 2091a7e5 | taeseongkim | SendStatusInterval = SaveStatusInterval, |
52 | 950e6b84 | taeseongkim | UseResolution = UseResolution, |
53 | FontsFolder = FontsFolder |
||
54 | 53c9637d | taeseongkim | }; |
55 | |||
56 | var sendData = ObjectToBytesStringConvert.ObjectToBytesString(processSendData); |
||
57 | 43e1d368 | taeseongkim | var convertPath = System.IO.Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "Convert\\Markus.Service.ConvertProcess.exe"); |
58 | 1d79913e | taeseongkim | |
59 | 53c9637d | taeseongkim | ProcessStartInfo startInfo = new ProcessStartInfo |
60 | { |
||
61 | UseShellExecute = false, |
||
62 | 43e1d368 | taeseongkim | FileName = convertPath, |
63 | 53c9637d | taeseongkim | WindowStyle = ProcessWindowStyle.Hidden, |
64 | CreateNoWindow = true, |
||
65 | ErrorDialog = false, |
||
66 | RedirectStandardError = false, |
||
67 | a5e5fff6 | taeseongkim | Arguments = $"{convertitem.ID.ToString()} {AESEncrypter.Encrypt(sendData)}" |
68 | 53c9637d | taeseongkim | //Arguments = $"{convertitem.ConvertID.ToString()} {convertitem.ProjectNumber} {AESEncrypter.Encrypt(MarkusDBConnectionString)} {gServiceHostAddress} {DownloadTempFolder} {MultiThreadMaxPages}" |
69 | }; |
||
70 | |||
71 | ConvertProcess.StartInfo = startInfo; |
||
72 | 1d79913e | taeseongkim | ConvertProcess.EnableRaisingEvents = true; |
73 | |||
74 | 53c9637d | taeseongkim | System.Diagnostics.Debug.WriteLine("convert process run : " + startInfo.Arguments); |
75 | |||
76 | a5e5fff6 | taeseongkim | logger.Info($"convert process run : ConvertDoc ID:{convertitem.ID}" + startInfo.Arguments); |
77 | 53c9637d | taeseongkim | |
78 | if (ConvertProcess.Start()) |
||
79 | { |
||
80 | try |
||
81 | { |
||
82 | var processAffinity = ProcessorAffinityList.Except(AliveConvertQueue.Select(f => (long)f.ProcessorAffinity)); |
||
83 | |||
84 | 43e1d368 | taeseongkim | long currentAffinity = 0; |
85 | |||
86 | 53c9637d | taeseongkim | if (processAffinity.Count() > 0) |
87 | { |
||
88 | 43e1d368 | taeseongkim | currentAffinity = processAffinity.First(); |
89 | 53c9637d | taeseongkim | |
90 | //int bitMask = 1 << (convertitem.ProcessorAffinity - 1); |
||
91 | //bitMask |= 1 << (anotherUserSelection - 1); / // 프로세스 두개 이상 선택 |
||
92 | |||
93 | 43e1d368 | taeseongkim | ConvertProcess.ProcessorAffinity = new IntPtr(currentAffinity); |
94 | a5e5fff6 | taeseongkim | logger.Info($"convert process currentAffinity set {currentAffinity} : ConvertDoc ID:{convertitem.ID}"); |
95 | 53c9637d | taeseongkim | |
96 | } |
||
97 | else |
||
98 | { |
||
99 | // 모두 사용중일때 점유율이 작은 걸로 사용 |
||
100 | 1d79913e | taeseongkim | var CurrentProcessAffinity = AliveConvertQueue.Where(x=>x.ProcessorAffinity > 0).Select(f => f.ProcessorAffinity).Distinct(); |
101 | 43e1d368 | taeseongkim | |
102 | currentAffinity = CurrentProcessAffinity.Min(); |
||
103 | ConvertProcess.ProcessorAffinity = new IntPtr(currentAffinity); |
||
104 | 53c9637d | taeseongkim | |
105 | a5e5fff6 | taeseongkim | logger.Info($"convert process Affinity All use {currentAffinity} : ConvertDoc ID:{convertitem.ID}"); |
106 | 53c9637d | taeseongkim | |
107 | 43e1d368 | taeseongkim | } |
108 | |||
109 | var item = AliveConvertQueue.Find(x => x.Equals(convertitem)); |
||
110 | |||
111 | if (item != null) |
||
112 | { |
||
113 | item.ProcessorAffinity = currentAffinity; |
||
114 | 53c9637d | taeseongkim | } |
115 | } |
||
116 | catch (Exception ex) |
||
117 | { |
||
118 | 43e1d368 | taeseongkim | AliveConvertQueue.Remove(convertitem); |
119 | d91efe5c | taeseongkim | logger.Error("ConvertProcessStart error", ex); |
120 | 53c9637d | taeseongkim | } |
121 | |||
122 | a5e5fff6 | taeseongkim | logger.Info($"convert process run true ConvertDoc ID:{convertitem.ID}"); |
123 | 53c9637d | taeseongkim | result = true; |
124 | } |
||
125 | } |
||
126 | catch (Exception ex) |
||
127 | { |
||
128 | 43e1d368 | taeseongkim | AliveConvertQueue.Remove(convertitem); |
129 | a5e5fff6 | taeseongkim | throw new Exception("ConvertThread " + $" ConvertDoc ID:{convertitem.ID} {convertitem.PROJECT_NO} {AESEncrypter.Encrypt(MarkusDBConnectionString)} {gServiceHostAddress} {DownloadTempFolder} {MultiThreadMaxPages}", ex.InnerException); |
130 | 53c9637d | taeseongkim | } |
131 | finally |
||
132 | { |
||
133 | //GC.WaitForPendingFinalizers(); |
||
134 | //GC.Collect(2); |
||
135 | //GC.Collect(2); |
||
136 | } |
||
137 | |||
138 | return result; |
||
139 | } |
||
140 | 0157b158 | taeseongkim | |
141 | 53c9637d | taeseongkim | /// <summary> |
142 | /// DB에 있는 대기중인 Item을 가져온다. |
||
143 | /// </summary> |
||
144 | public void setDataBaseWaitingList() |
||
145 | { |
||
146 | a5e5fff6 | taeseongkim | using (ConvertDocRepository database = new ConvertDocRepository(MarkusDBConnectionString)) |
147 | 53c9637d | taeseongkim | { |
148 | a5e5fff6 | taeseongkim | int totalProcessCount = this.ServiceProperty.PROCESS_COUNT + StationServiceList.Where(x => x.IsOnline).Sum(f => f.Properties.PROCESS_COUNT); |
149 | 0157b158 | taeseongkim | |
150 | a5e5fff6 | taeseongkim | var convertItems = database.GetWaitorErrorAsync(totalProcessCount).GetAwaiter().GetResult(); |
151 | ff4b1e6e | taeseongkim | |
152 | a5e5fff6 | taeseongkim | foreach (var convert in convertItems) |
153 | 1ae729e4 | taeseongkim | { |
154 | a5e5fff6 | taeseongkim | //ReflashSubService(); |
155 | |||
156 | if (AliveConvertQueue.Count(x => x.ID == convert.ID || x.DOCUMENT_ID == convert.DOCUMENT_ID) == 0) |
||
157 | 0157b158 | taeseongkim | { |
158 | a5e5fff6 | taeseongkim | if (convert.STATUS > (int)StatusCodeType.None) |
159 | 43e1d368 | taeseongkim | { |
160 | a5e5fff6 | taeseongkim | var result = database.SetCleanUpItemAsync(convert.ID, 1).GetAwaiter().GetResult(); |
161 | |||
162 | if (result != 1) |
||
163 | { |
||
164 | throw new Exception($"SetCleanUpItem result :{result} {convert.ID}"); |
||
165 | } |
||
166 | 43e1d368 | taeseongkim | } |
167 | a5e5fff6 | taeseongkim | |
168 | ConvertProcessAdd(convert.PROJECT_NO, convert.ID); |
||
169 | //PassConvertItem(convert.PROJECT_NO, convert.ID, convert.DOCUMENT_ID); |
||
170 | |||
171 | //System.Threading.Thread.Sleep(1000); |
||
172 | 0157b158 | taeseongkim | } |
173 | a5e5fff6 | taeseongkim | #if DEBUG |
174 | else |
||
175 | { |
||
176 | if (AliveConvertQueue.Count(x => x.ID == convert.ID) > 0) |
||
177 | { |
||
178 | if (System.Environment.UserInteractive) |
||
179 | { |
||
180 | Console.WriteLine($"AliveConvertQueue.Count(x => x.ID == convert.ID) : {convert.ID}"); |
||
181 | } |
||
182 | } |
||
183 | 1ae729e4 | taeseongkim | |
184 | a5e5fff6 | taeseongkim | if (AliveConvertQueue.Count(x=> x.DOCUMENT_ID == convert.DOCUMENT_ID) > 0) |
185 | { |
||
186 | if (System.Environment.UserInteractive) |
||
187 | { |
||
188 | Console.WriteLine($"AliveConvertQueue.Count(x.DOCUMENT_ID == convert.DOCUMENT_ID) : {convert.DOCUMENT_ID}"); |
||
189 | } |
||
190 | } |
||
191 | |||
192 | } |
||
193 | #endif |
||
194 | /// 2022.11.28 수정 |
||
195 | if (AliveConvertQueue.Count >= this.ServiceProperty.PROCESS_COUNT) |
||
196 | { |
||
197 | break; |
||
198 | } |
||
199 | 43e1d368 | taeseongkim | } |
200 | 53c9637d | taeseongkim | } |
201 | 0157b158 | taeseongkim | } |
202 | 53c9637d | taeseongkim | |
203 | a5e5fff6 | taeseongkim | /// <summary> |
204 | /// DB에 있는 대기중인 Item을 가져온다. |
||
205 | /// </summary> |
||
206 | //public void setDataBaseWaitingLista() |
||
207 | //{ |
||
208 | |||
209 | // List<EntityModel.CONVERTER_DOC> convertItems = new List<EntityModel.CONVERTER_DOC>(); |
||
210 | |||
211 | // using (DataBase.ConvertDatabase database = new DataBase.ConvertDatabase(MarkusDBConnectionString)) |
||
212 | // { |
||
213 | // // 전체 서비스의 process count 만큼 waiting item을 가져온다. |
||
214 | // int totalProcessCount = this.ServiceProperty.PROCESS_COUNT + StationServiceList.Where(x => x.IsOnline).Sum(f => f.Properties.PROCESS_COUNT); |
||
215 | // convertItems = database.GetWaitConvertItems(this.RunProjectList, totalProcessCount).ToList(); |
||
216 | // } |
||
217 | |||
218 | // foreach (var convert in convertItems) |
||
219 | // { |
||
220 | // //ReflashSubService(); |
||
221 | |||
222 | // if (AliveConvertQueue.Count(x => x.ConvertID == convert.ID) == 0) |
||
223 | // { |
||
224 | // if (convert.STATUS > (int)StatusCodeType.None) |
||
225 | // { |
||
226 | // using (DataBase.ConvertDatabase database = new DataBase.ConvertDatabase(MarkusDBConnectionString)) |
||
227 | // { |
||
228 | // database.SetCleanUpItem(convert.ID, 1); |
||
229 | // } |
||
230 | // } |
||
231 | // ConvertProcessAdd(convert.PROJECT_NO, convert.ID); |
||
232 | // //PassConvertItem(convert.PROJECT_NO, convert.ID, convert.DOCUMENT_ID); |
||
233 | |||
234 | // //System.Threading.Thread.Sleep(1000); |
||
235 | // } |
||
236 | |||
237 | // /// 2022.11.28 수정 |
||
238 | // if (AliveConvertQueue.Count >= this.ServiceProperty.PROCESS_COUNT) |
||
239 | // { |
||
240 | // break; |
||
241 | // } |
||
242 | // } |
||
243 | |||
244 | //} |
||
245 | |||
246 | ff4b1e6e | taeseongkim | public bool IsDataBaseWaitingList(int overListCount) |
247 | { |
||
248 | bool result = false; |
||
249 | |||
250 | try |
||
251 | { |
||
252 | a5e5fff6 | taeseongkim | using (ConvertDocRepository convertDatabase = new ConvertDocRepository(MarkusDBConnectionString)) |
253 | ff4b1e6e | taeseongkim | { |
254 | a5e5fff6 | taeseongkim | var convertItems = convertDatabase.GetWaitorErrorAsync(overListCount).GetAwaiter().GetResult(); |
255 | ff4b1e6e | taeseongkim | |
256 | if (convertItems.Count() > 0) |
||
257 | { |
||
258 | result = true; |
||
259 | } |
||
260 | } |
||
261 | } |
||
262 | catch (Exception ex) |
||
263 | { |
||
264 | logger.Error($"IsDataBaseWaitingList Error",ex); |
||
265 | } |
||
266 | |||
267 | return result; |
||
268 | } |
||
269 | |||
270 | 43e1d368 | taeseongkim | private async Task<bool> ReflashSubServiceAsync() |
271 | 0157b158 | taeseongkim | { |
272 | 43e1d368 | taeseongkim | bool result = false; |
273 | |||
274 | try |
||
275 | 0157b158 | taeseongkim | { |
276 | 43e1d368 | taeseongkim | foreach (var subservice in StationServiceList) |
277 | 0157b158 | taeseongkim | { |
278 | 43e1d368 | taeseongkim | try |
279 | 06f13e11 | taeseongkim | { |
280 | 43e1d368 | taeseongkim | subservice.IsOnline = await SytemNet.PingAsync(subservice.Properties.SERVICE_ADDRESS); |
281 | |||
282 | if (subservice.IsOnline) |
||
283 | { |
||
284 | var alivelist = await subservice.Service.AliveConvertListAsync(); |
||
285 | 06f13e11 | taeseongkim | |
286 | a5e5fff6 | taeseongkim | subservice.ConvertItems = alivelist.Cast<ConvertDoc>().ToList(); |
287 | 43e1d368 | taeseongkim | subservice.AliveCount = alivelist.Count(); |
288 | } |
||
289 | else |
||
290 | { |
||
291 | logger.Error($"Connection Error {subservice.Properties.SERVICE_ADDRESS}"); |
||
292 | a5e5fff6 | taeseongkim | subservice.ConvertItems = new List<ConvertDoc>(); |
293 | 43e1d368 | taeseongkim | subservice.AliveCount = subservice.Properties.PROCESS_COUNT; |
294 | } |
||
295 | |||
296 | result = true; |
||
297 | 06f13e11 | taeseongkim | } |
298 | 43e1d368 | taeseongkim | catch (Exception ex) |
299 | 06f13e11 | taeseongkim | { |
300 | 43e1d368 | taeseongkim | logger.Error($"ReflashSubService error - Service ID : {subservice.Properties.ID} ", ex); |
301 | 06f13e11 | taeseongkim | } |
302 | 0157b158 | taeseongkim | } |
303 | 6f6e7dbf | taeseongkim | } |
304 | 43e1d368 | taeseongkim | catch (Exception ex) |
305 | { |
||
306 | logger.Error($"ReflashSubService error", ex); |
||
307 | } |
||
308 | |||
309 | return result; |
||
310 | 6f6e7dbf | taeseongkim | } |
311 | |||
312 | 06f13e11 | taeseongkim | |
313 | 0a89a17f | taeseongkim | /// <summary> |
314 | /// |
||
315 | /// </summary> |
||
316 | /// <param name="ProjectNo"></param> |
||
317 | /// <param name="ConvertID"></param> |
||
318 | /// <param name="UniqueKey">Document ID(문서의 유일키)</param> |
||
319 | a5e5fff6 | taeseongkim | private async void PassConvertItem(string ProjectNo,string ConvertDocID,bool isSubStation = false) |
320 | 6f6e7dbf | taeseongkim | { |
321 | try |
||
322 | { |
||
323 | 43e1d368 | taeseongkim | IEnumerable<SubStationServiceItem> stationList = null; |
324 | |||
325 | //if (!isSubStation) |
||
326 | //{ |
||
327 | stationList = StationServiceList.Where(x => x.IsOnline); |
||
328 | //} |
||
329 | //else |
||
330 | //{ |
||
331 | // stationList = StationServiceList.Where(x => x.Properties.ID != this.ServiceID && x.IsOnline); |
||
332 | //} |
||
333 | 06f13e11 | taeseongkim | |
334 | a5e5fff6 | taeseongkim | if (stationList.SelectMany(x => x.ConvertItems).Count(c => c.PROJECT_NO == ProjectNo && c.ID == ConvertDocID) == 0) |
335 | 6f6e7dbf | taeseongkim | { |
336 | 06f13e11 | taeseongkim | var station = stationList.OrderByDescending(x => x.Properties.PROCESS_COUNT - x.AliveCount).FirstOrDefault(); |
337 | 6f6e7dbf | taeseongkim | |
338 | if (station != null) |
||
339 | { |
||
340 | 60723dc9 | taeseongkim | if (station.Properties.PROCESS_COUNT - station.AliveCount > 0) |
341 | ff4b1e6e | taeseongkim | { |
342 | 60723dc9 | taeseongkim | System.Diagnostics.Debug.WriteLine($"{station.Properties.SERVICE_ADDRESS} {station.Properties.PROCESS_COUNT}/{station.AliveCount}"); |
343 | a5e5fff6 | taeseongkim | var result = await station.Service.PassConvertAsync(ProjectNo, ConvertDocID); |
344 | 60723dc9 | taeseongkim | |
345 | if (!result.IsNullOrEmpty()) |
||
346 | { |
||
347 | if (result.ToLower() == true.ToString().ToLower()) |
||
348 | { |
||
349 | a5e5fff6 | taeseongkim | Console.WriteLine($"PassConvertItem - Service ID : {station.Properties.ID} ConvertDocID : {ConvertDocID}"); |
350 | logger.Info($"PassConvertItem - Service ID : {station.Properties.ID} ConvertDocID : {ConvertDocID}"); |
||
351 | 43e1d368 | taeseongkim | |
352 | 60723dc9 | taeseongkim | station.AliveCount++; |
353 | } |
||
354 | 43e1d368 | taeseongkim | else |
355 | { |
||
356 | a5e5fff6 | taeseongkim | logger.Error($"PassConvertItem Error result : {result} - Service ID : {station.Properties.ID} ConvertDocID : {ConvertDocID}"); |
357 | 43e1d368 | taeseongkim | } |
358 | 60723dc9 | taeseongkim | } |
359 | else |
||
360 | { |
||
361 | a5e5fff6 | taeseongkim | logger.Error($"PassConvertItem result: Nulll; - Service ID : {station.Properties.ID} ConvertDocID : {ConvertDocID}"); |
362 | 60723dc9 | taeseongkim | System.Diagnostics.Debug.WriteLine("result : Nulll;"); |
363 | } |
||
364 | ff4b1e6e | taeseongkim | } |
365 | 6f6e7dbf | taeseongkim | } |
366 | 0157b158 | taeseongkim | } |
367 | } |
||
368 | 6f6e7dbf | taeseongkim | catch (Exception ex) |
369 | { |
||
370 | logger.Error($"setDataBaseWaitingList", ex); |
||
371 | } |
||
372 | 0157b158 | taeseongkim | } |
373 | |||
374 | ff4b1e6e | taeseongkim | /// <summary> |
375 | /// 컨버터 프로세스와 AiliveItems을 비교하여 AliveItems에 없는 경우 AliveItems을 제거 |
||
376 | /// </summary> |
||
377 | 06f13e11 | taeseongkim | private void CleanUpAliveQueueItems() |
378 | { |
||
379 | ff4b1e6e | taeseongkim | if (AliveConvertQueue.Count() > 0) |
380 | 06f13e11 | taeseongkim | { |
381 | ff4b1e6e | taeseongkim | var processList = Process.GetProcessesByName("Markus.Service.ConvertProcess"); |
382 | 06f13e11 | taeseongkim | |
383 | ff4b1e6e | taeseongkim | if (processList.Length == 0) |
384 | 06f13e11 | taeseongkim | { |
385 | ff4b1e6e | taeseongkim | AliveConvertQueue.Clear(); |
386 | System.Diagnostics.Debug.WriteLine("AliveConvertQueue.Clear()"); |
||
387 | } |
||
388 | else |
||
389 | { |
||
390 | a5e5fff6 | taeseongkim | var argumentList = processList.Where(x=> !x.HasExited).Select(f => f.Arguments().CommandLine).SelectMany(f => f).ToList(); |
391 | ff4b1e6e | taeseongkim | |
392 | a5e5fff6 | taeseongkim | List<ConvertDoc> convertItems = AliveConvertQueue; |
393 | 60723dc9 | taeseongkim | |
394 | try |
||
395 | 06f13e11 | taeseongkim | { |
396 | d91efe5c | taeseongkim | if (convertItems.Count() > 0 && argumentList.Count() > 0) |
397 | ff4b1e6e | taeseongkim | { |
398 | 1ae729e4 | taeseongkim | for (int i = convertItems.Count - 1; i >= 0; --i) |
399 | 60723dc9 | taeseongkim | { |
400 | a5e5fff6 | taeseongkim | if (argumentList.Count(x => x == convertItems[i].ID) == 0) |
401 | 1ae729e4 | taeseongkim | { |
402 | a5e5fff6 | taeseongkim | System.Diagnostics.Debug.WriteLine($"AliveConvertQueue remove {convertItems[i].ID}"); |
403 | logger.Warn($"AliveConvertQueue remove {convertItems[i].ID}"); |
||
404 | 43e1d368 | taeseongkim | AliveConvertQueue.Remove(convertItems[i]); |
405 | |||
406 | 1ae729e4 | taeseongkim | } |
407 | 60723dc9 | taeseongkim | } |
408 | ff4b1e6e | taeseongkim | } |
409 | 06f13e11 | taeseongkim | } |
410 | 60723dc9 | taeseongkim | catch (Exception ex) |
411 | { |
||
412 | d91efe5c | taeseongkim | logger.Error("CleanUpAliveQueueItems error",ex); |
413 | 60723dc9 | taeseongkim | } |
414 | 06f13e11 | taeseongkim | } |
415 | } |
||
416 | } |
||
417 | |||
418 | ff4b1e6e | taeseongkim | /// <summary> |
419 | 60723dc9 | taeseongkim | /// AliveConvertQueue와 db를 비교하여 AliveConvertQueue에 없는 데이터를 초기화 하여 다시 컨버팅 |
420 | ff4b1e6e | taeseongkim | /// </summary> |
421 | private async void CleanUpDataBaseItems() |
||
422 | 0157b158 | taeseongkim | { |
423 | 150747cb | taeseongkim | try |
424 | 53c9637d | taeseongkim | { |
425 | a5e5fff6 | taeseongkim | int totalProcessCount = this.ServiceProperty.PROCESS_COUNT + StationServiceList.Where(x => x.IsOnline).Sum(f => f.Properties.PROCESS_COUNT); |
426 | |||
427 | using (DataBase.Repositories.ConvertDocRepository repository = new DataBase.Repositories.ConvertDocRepository(MarkusDBConnectionString)) |
||
428 | 150747cb | taeseongkim | { |
429 | a5e5fff6 | taeseongkim | var items = repository.GetConvertingItemAsync(totalProcessCount).GetAwaiter().GetResult(); |
430 | |||
431 | List<ConvertDoc> aliveItems = new List<ConvertDoc>(); |
||
432 | 53c9637d | taeseongkim | |
433 | a5e5fff6 | taeseongkim | aliveItems.AddRange(this.AliveConvertList()); |
434 | 0157b158 | taeseongkim | |
435 | 60723dc9 | taeseongkim | foreach (var item in StationServiceList.Where(x => x.IsOnline)) |
436 | 0157b158 | taeseongkim | { |
437 | ff4b1e6e | taeseongkim | var serviceItems = await item.Service.AliveConvertListAsync(); |
438 | a5e5fff6 | taeseongkim | aliveItems.AddRange(serviceItems.Cast<ConvertDoc>()); |
439 | 0157b158 | taeseongkim | } |
440 | 60723dc9 | taeseongkim | |
441 | 43e1d368 | taeseongkim | if (aliveItems.Count() > 0) |
442 | 53c9637d | taeseongkim | { |
443 | a5e5fff6 | taeseongkim | logger.Warn($"aliveItems : {string.Join(",",aliveItems.Select(x=>x.ID))}"); |
444 | 43e1d368 | taeseongkim | |
445 | foreach (var item in items) |
||
446 | 60723dc9 | taeseongkim | { |
447 | a5e5fff6 | taeseongkim | if (aliveItems.Count(x => x.ID == item.ID) == 0) |
448 | 43e1d368 | taeseongkim | { |
449 | Console.WriteLine($"SetCleanUpItem : {item.ID}"); |
||
450 | logger.Warn($"SetCleanUpItem : {item.ID}"); |
||
451 | a5e5fff6 | taeseongkim | repository.SetCleanUpItemAsync(item.ID, 0).GetAwaiter().GetResult(); |
452 | 43e1d368 | taeseongkim | } |
453 | 60723dc9 | taeseongkim | } |
454 | 53c9637d | taeseongkim | } |
455 | 150747cb | taeseongkim | |
456 | 53c9637d | taeseongkim | } |
457 | 150747cb | taeseongkim | } |
458 | catch (Exception ex) |
||
459 | { |
||
460 | throw new Exception("CleanUpDataBaseItems Error ", ex); |
||
461 | 53c9637d | taeseongkim | } |
462 | } |
||
463 | |||
464 | public void Stopprocess() |
||
465 | { |
||
466 | var process = Process.GetProcessesByName("Markus.Service.ConvertProcess"); |
||
467 | |||
468 | for (int i = process.Count() - 1; i >= 0 ; i--) |
||
469 | { |
||
470 | try |
||
471 | { |
||
472 | Console.WriteLine($"{i} Process Kill"); |
||
473 | process[i].Kill(); |
||
474 | } |
||
475 | catch (Exception ex) |
||
476 | { |
||
477 | System.Diagnostics.Debug.WriteLine(ex.ToString()); |
||
478 | } |
||
479 | } |
||
480 | } |
||
481 | |||
482 | /// <summary> |
||
483 | /// finish가 호출되고 살아있는 프로세스라고 추정됨 |
||
484 | /// </summary> |
||
485 | public void DeadLockProcessKill() |
||
486 | { |
||
487 | var process = Process.GetProcessesByName("Markus.Service.ConvertProcess"); |
||
488 | |||
489 | for (int i = process.Count() - 1; i >= 0; i--) |
||
490 | { |
||
491 | try |
||
492 | { |
||
493 | var commandLines = process[i].Arguments().CommandLine; |
||
494 | |||
495 | if (commandLines.Count() > 0) |
||
496 | { |
||
497 | a5e5fff6 | taeseongkim | if (ServiceStation.AliveConvertQueue.Count(f => f.ID == commandLines[0]) == 0) |
498 | 53c9637d | taeseongkim | { |
499 | process[i].Kill(); |
||
500 | } |
||
501 | } |
||
502 | } |
||
503 | catch (Exception ex) |
||
504 | { |
||
505 | System.Diagnostics.Debug.WriteLine(ex.ToString()); |
||
506 | } |
||
507 | } |
||
508 | } |
||
509 | |||
510 | a5e5fff6 | taeseongkim | private async void ConvertFinish(ConvertDoc convertitem) |
511 | 53c9637d | taeseongkim | { |
512 | try |
||
513 | { |
||
514 | a5e5fff6 | taeseongkim | System.Diagnostics.Debug.WriteLine("Convert Finish : " + convertitem.ID); |
515 | 53c9637d | taeseongkim | |
516 | System.Diagnostics.Debug.WriteLine("ServiceStation.AliveConvertQueue.Count() : " + ServiceStation.AliveConvertQueue.Count()); |
||
517 | 1d79913e | taeseongkim | |
518 | a5e5fff6 | taeseongkim | List<string> deleteItems = new List<string> { convertitem.ID }; |
519 | 1d79913e | taeseongkim | |
520 | |||
521 | a5e5fff6 | taeseongkim | ServiceStation.AliveConvertQueue.RemoveAll(x=>deleteItems.Any(y=>y == x.ID)); |
522 | 53c9637d | taeseongkim | |
523 | System.Diagnostics.Debug.WriteLine("ServiceStation.AliveConvertQueue.Count() : " + ServiceStation.AliveConvertQueue.Count()); |
||
524 | |||
525 | 06f13e11 | taeseongkim | if (IsStation) |
526 | { |
||
527 | 43e1d368 | taeseongkim | if (!IsReleaseItems) |
528 | { |
||
529 | System.Diagnostics.Debug.WriteLine("ConvertFinish ReleaseItems call"); |
||
530 | ReleaseItems(); |
||
531 | } |
||
532 | 06f13e11 | taeseongkim | } |
533 | else |
||
534 | { |
||
535 | if (StationClient != null) |
||
536 | { |
||
537 | 60723dc9 | taeseongkim | await StationClient.ReleaseConvertItemsAsync(); |
538 | 06f13e11 | taeseongkim | } |
539 | } |
||
540 | 0157b158 | taeseongkim | //if (ServiceStation.AliveConvertQueue.Count() < MultiProcessCount) |
541 | //{ |
||
542 | // setDataBaseWaitingList(); |
||
543 | //} |
||
544 | 53c9637d | taeseongkim | } |
545 | catch (Exception ex) |
||
546 | { |
||
547 | logger.Error("ConvertFinish Error",ex); |
||
548 | } |
||
549 | } |
||
550 | } |
||
551 | } |