Commit 883da59384780819a5040c8400f95debb611d377
1 parent
980c5686
.
Showing
3 changed files
with
62 additions
and
100 deletions
Show diff stats
src/main/java/com/batch/controller/JobController.java
| @@ -34,16 +34,7 @@ public class JobController { | @@ -34,16 +34,7 @@ public class JobController { | ||
| 34 | @Autowired | 34 | @Autowired |
| 35 | private JobService jobService; | 35 | private JobService jobService; |
| 36 | @Autowired | 36 | @Autowired |
| 37 | - private MatchingInnerDelingMapper matchingInnerDelingMapper; | ||
| 38 | - @Value("${thread.ai.count.rowmax}") | ||
| 39 | - BigDecimal bdAiAsyncMaxRowCount; | ||
| 40 | - @Value("${thread.ai.processing.wait}") | ||
| 41 | - BigDecimal bdAiAsyncWaitTime; | ||
| 42 | - @Value("${thread.ai.processing.wait.total}") | ||
| 43 | - BigDecimal bdAiAsyncTotalWaitTime; | ||
| 44 | - | ||
| 45 | - | ||
| 46 | - | 37 | + private MatchingInnerDelingMapper matchingInnerDelingMapper; |
| 47 | 38 | ||
| 48 | /** | 39 | /** |
| 49 | * TODO : AI 서버에 특정 경로에 생성되는 파일을 읽는(끝에 50줄 정도) API | 40 | * TODO : AI 서버에 특정 경로에 생성되는 파일을 읽는(끝에 50줄 정도) API |
| @@ -214,43 +205,7 @@ public class JobController { | @@ -214,43 +205,7 @@ public class JobController { | ||
| 214 | String sJobGroup = uuid.toString(); | 205 | String sJobGroup = uuid.toString(); |
| 215 | 206 | ||
| 216 | log.info("Start AI Matching Job"); | 207 | log.info("Start AI Matching Job"); |
| 217 | - List<Map> retData = matchingInnerDelingMapper.getAiReadData(params); | ||
| 218 | - BigDecimal bdCurrentRowCount = BigDecimal.ZERO; | ||
| 219 | - for(Map curMap : retData) { | ||
| 220 | - Map<String, Object> curMParams = new HashMap<String, Object>(); | ||
| 221 | - curMParams.putAll(curMap); | ||
| 222 | - curMParams.put("error_range", params.get("error_range")); | ||
| 223 | - | ||
| 224 | - BigDecimal bdCntAll = new BigDecimal(String.valueOf(curMap.get("cnt_all"))); | ||
| 225 | - bdCurrentRowCount = bdCurrentRowCount.add(bdCntAll); | ||
| 226 | - log.info("Call Matching Job (" + JsonUtil.objectToString(curMap) + ")"); | ||
| 227 | - jobService.aiJobSub(sJobGroup, curMParams); | ||
| 228 | - | ||
| 229 | - //전체카운트가 처리가능카운트를 넘어설때 | ||
| 230 | - if (bdCurrentRowCount.compareTo(bdAiAsyncMaxRowCount) > -1) { | ||
| 231 | - bdCurrentRowCount = BigDecimal.ZERO; | ||
| 232 | - | ||
| 233 | - //현재 작업그룹이 종료가 되었는지 체크해서 종료시 카운트 초기화 하고 다음작업을 한다. | ||
| 234 | - boolean blnStatus = true; | ||
| 235 | - Integer iTotalWait = 0; | ||
| 236 | - Integer iWaitTime = bdAiAsyncWaitTime.intValue() * 1000; //밀리초 | ||
| 237 | - do { | ||
| 238 | - Map<String, Object> mParam = new HashMap<String, Object>(); | ||
| 239 | - mParam.put("userJobGroup", sJobGroup); | ||
| 240 | - List<Map> lmJob = matchingInnerDelingMapper.getUserJobStatus(mParam); | ||
| 241 | - for (Map curJob : lmJob) { | ||
| 242 | - String ScurStatus = (String) curJob.get("status"); | ||
| 243 | - if (!"Finished".equalsIgnoreCase(ScurStatus)) { | ||
| 244 | - blnStatus = false; | ||
| 245 | - Thread.sleep(iWaitTime); | ||
| 246 | - iTotalWait = iTotalWait + iWaitTime; | ||
| 247 | - break; | ||
| 248 | - } | ||
| 249 | - } | ||
| 250 | - } while (!blnStatus && iTotalWait < bdAiAsyncTotalWaitTime.intValue()); //전체 기다리는 시간까지 체크 | ||
| 251 | - log.info("Next Thread Group Processing"); | ||
| 252 | - } | ||
| 253 | - } | 208 | + jobService.aiJobSub(sJobGroup, params); |
| 254 | log.info("End AI Matching Job"); | 209 | log.info("End AI Matching Job"); |
| 255 | 210 | ||
| 256 | Map<String, String> rtnMap = new HashMap<String, String>(); | 211 | Map<String, String> rtnMap = new HashMap<String, String>(); |
src/main/java/com/batch/service/JobService.java
| @@ -36,6 +36,7 @@ import com.batch.config.MatchingSetup.Matching; | @@ -36,6 +36,7 @@ import com.batch.config.MatchingSetup.Matching; | ||
| 36 | import com.batch.mapper.primary.MatchingInnerDelingMapper; | 36 | import com.batch.mapper.primary.MatchingInnerDelingMapper; |
| 37 | import com.batch.mapper.secondary.OracleMapper; | 37 | import com.batch.mapper.secondary.OracleMapper; |
| 38 | import com.batch.util.FileUtil; | 38 | import com.batch.util.FileUtil; |
| 39 | +import com.batch.util.JsonUtil; | ||
| 39 | import com.batch.util.StringUtil; | 40 | import com.batch.util.StringUtil; |
| 40 | import com.batch.service.JobService; | 41 | import com.batch.service.JobService; |
| 41 | import lombok.extern.slf4j.Slf4j; | 42 | import lombok.extern.slf4j.Slf4j; |
| @@ -53,6 +54,15 @@ public class JobService { | @@ -53,6 +54,15 @@ public class JobService { | ||
| 53 | @Value("${matching.auto.exceptListByComma}") | 54 | @Value("${matching.auto.exceptListByComma}") |
| 54 | String sExceptMatchType; | 55 | String sExceptMatchType; |
| 55 | 56 | ||
| 57 | + @Value("${thread.ai.count.rowmax}") | ||
| 58 | + BigDecimal bdAiAsyncMaxRowCount; | ||
| 59 | + | ||
| 60 | + @Value("${thread.ai.processing.wait}") | ||
| 61 | + BigDecimal bdAiAsyncWaitTime; | ||
| 62 | + | ||
| 63 | + @Value("${thread.ai.processing.wait.total}") | ||
| 64 | + BigDecimal bdAiAsyncTotalWaitTime; | ||
| 65 | + | ||
| 56 | @Autowired | 66 | @Autowired |
| 57 | private JobLauncher jobLauncher; | 67 | private JobLauncher jobLauncher; |
| 58 | 68 | ||
| @@ -282,63 +292,60 @@ public class JobService { | @@ -282,63 +292,60 @@ public class JobService { | ||
| 282 | matchingInnerDelingMapper.finishUserJob(paramLog); | 292 | matchingInnerDelingMapper.finishUserJob(paramLog); |
| 283 | 293 | ||
| 284 | } | 294 | } |
| 285 | - | 295 | + |
| 286 | @SuppressWarnings("rawtypes") | 296 | @SuppressWarnings("rawtypes") |
| 287 | @Async("aiAsync") | 297 | @Async("aiAsync") |
| 288 | - public void aiJobSub(String jobGroupId, Map paramRec) throws Exception { | ||
| 289 | - | ||
| 290 | - | ||
| 291 | - //Job Create Log | ||
| 292 | - UUID uuid = UUID.randomUUID(); | ||
| 293 | - HashMap<String, String> mt = new HashMap<String, String>(); | ||
| 294 | - SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss"); | ||
| 295 | - String sDate = dateFormat.format(new Date()) + ":" + uuid.toString(); | ||
| 296 | - | ||
| 297 | - Map<String, Object> paramLog = new HashMap<String, Object>(); | ||
| 298 | - paramLog.put("user_job_group", jobGroupId); | ||
| 299 | - paramLog.put("user_job_id", sDate); | ||
| 300 | - paramLog.put("user_job_name", "AI매칭(" + paramRec.toString() + ")"); | ||
| 301 | - matchingInnerDelingMapper.createUserJob(paramLog); | ||
| 302 | - | ||
| 303 | - | ||
| 304 | - long startTime = System.currentTimeMillis(); | ||
| 305 | - log.info("ai Job Started : " + startTime); | ||
| 306 | - log.debug("ai Job params=" + paramRec.toString()); | ||
| 307 | - | ||
| 308 | - String sSysSe = (String) paramRec.get("sys_se"); | ||
| 309 | - String sAccnutYm = (String) paramRec.get("accnut_ym"); | ||
| 310 | - String sCprCode = (String) paramRec.get("cpr_code"); | ||
| 311 | - String sPartCpr = (String) paramRec.get("partn_cpr"); | ||
| 312 | - String sDelngCrncy = (String) paramRec.get("delng_crncy"); | ||
| 313 | - String sTbTy = (String) paramRec.get("tb_ty"); | ||
| 314 | - String sErrorRange = (String) paramRec.get("error_range"); | ||
| 315 | - | ||
| 316 | - String sThreadName = Thread.currentThread().getName(); | ||
| 317 | - | ||
| 318 | - log.debug("call python"); | ||
| 319 | - new ProcessExecutor() | ||
| 320 | - .command(sPythonPrg, sPythonAiTarget, sDate, sSysSe, sAccnutYm, sCprCode, sPartCpr, sDelngCrncy, sErrorRange, sTbTy) | ||
| 321 | - .redirectOutput(new LogOutputStream() { | ||
| 322 | - @Override | ||
| 323 | - protected void processLine(String line) { | ||
| 324 | - log.info(line); | ||
| 325 | - } | ||
| 326 | - }) | ||
| 327 | - .execute(); | ||
| 328 | - | ||
| 329 | - long endTime = System.currentTimeMillis(); | ||
| 330 | - log.info("ai Job Ended: " + endTime); | ||
| 331 | - log.info("ai Job Running Time : " + (endTime - startTime) + "ms"); | 298 | + public void aiJobSub(String jobGroupId, Map params) throws Exception { |
| 332 | 299 | ||
| 300 | + List<Map> retData = matchingInnerDelingMapper.getAiReadData(params); | ||
| 301 | + BigDecimal bdCurrentRowCount = BigDecimal.ZERO; | ||
| 333 | 302 | ||
| 334 | -// //작업종료에 대한 로그 업데이트 | ||
| 335 | -// paramLog.put("exit_code", "0"); | ||
| 336 | -// paramLog.put("exit_message", ""); | ||
| 337 | -// matchingInnerDelingMapper.finishUserJob(paramLog); | ||
| 338 | - | 303 | + List<ThreadAiMatching> lThread = new ArrayList<ThreadAiMatching>(); |
| 304 | + for(Map curMap : retData) { | ||
| 305 | + Map<String, Object> curMParams = new HashMap<String, Object>(); | ||
| 306 | + curMParams.putAll(curMap); | ||
| 307 | + curMParams.put("error_range", params.get("error_range")); | ||
| 308 | + | ||
| 309 | + BigDecimal bdCntAll = new BigDecimal(String.valueOf(curMap.get("cnt_all"))); | ||
| 310 | + bdCurrentRowCount = bdCurrentRowCount.add(bdCntAll); | ||
| 311 | + log.info("Call Matching Job (" + JsonUtil.objectToString(curMap) + ")"); | ||
| 312 | + ThreadAiMatching threadAiMatching = new ThreadAiMatching( | ||
| 313 | + jobGroupId, | ||
| 314 | + curMParams, | ||
| 315 | + matchingInnerDelingMapper, | ||
| 316 | + sPythonPrg, | ||
| 317 | + sPythonAiTarget | ||
| 318 | + ); | ||
| 319 | + threadAiMatching.start(); | ||
| 320 | + | ||
| 321 | + //전체카운트가 처리가능카운트를 넘어설때 | ||
| 322 | + if (bdCurrentRowCount.compareTo(bdAiAsyncMaxRowCount) > -1) { | ||
| 323 | + bdCurrentRowCount = BigDecimal.ZERO; | ||
| 324 | + | ||
| 325 | + //현재 작업그룹이 종료가 되었는지 체크해서 종료시 카운트 초기화 하고 다음작업을 한다. | ||
| 326 | + boolean blnStatus = true; | ||
| 327 | + Integer iTotalWait = 0; | ||
| 328 | + Integer iWaitTime = bdAiAsyncWaitTime.intValue() * 1000; //밀리초 | ||
| 329 | + do { | ||
| 330 | + Map<String, Object> mParam = new HashMap<String, Object>(); | ||
| 331 | + mParam.put("userJobGroup", jobGroupId); | ||
| 332 | + List<Map> lmJob = matchingInnerDelingMapper.getUserJobStatus(mParam); | ||
| 333 | + for (Map curJob : lmJob) { | ||
| 334 | + String ScurStatus = (String) curJob.get("status"); | ||
| 335 | + if (!"Finished".equalsIgnoreCase(ScurStatus)) { | ||
| 336 | + blnStatus = false; | ||
| 337 | + Thread.sleep(iWaitTime); | ||
| 338 | + iTotalWait = iTotalWait + iWaitTime; | ||
| 339 | + break; | ||
| 340 | + } | ||
| 341 | + } | ||
| 342 | + } while (!blnStatus && iTotalWait < bdAiAsyncTotalWaitTime.intValue()); //전체 기다리는 시간까지 체크 | ||
| 343 | + log.info("Next Thread Group Processing"); | ||
| 344 | + } | ||
| 345 | + } | ||
| 346 | + log.info("Current Group Process End"); | ||
| 339 | } | 347 | } |
| 340 | 348 | ||
| 341 | - | ||
| 342 | public JobExecution invokeJob(String jobName, String jobType, Map<String, String> params) throws JobInstanceAlreadyCompleteException, JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException { | 349 | public JobExecution invokeJob(String jobName, String jobType, Map<String, String> params) throws JobInstanceAlreadyCompleteException, JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException { |
| 343 | 350 | ||
| 344 | UUID uuid = UUID.randomUUID(); | 351 | UUID uuid = UUID.randomUUID(); |
src/main/resources/application.properties
| @@ -46,7 +46,7 @@ decorator.datasource.p6spy.enable-logging=true | @@ -46,7 +46,7 @@ decorator.datasource.p6spy.enable-logging=true | ||
| 46 | 46 | ||
| 47 | logging.level.root=info | 47 | logging.level.root=info |
| 48 | logging.level.com.batch=info | 48 | logging.level.com.batch=info |
| 49 | -logging.level.p6spy=off | 49 | +logging.level.p6spy=debug |
| 50 | 50 | ||
| 51 | #Thread Count 설정 | 51 | #Thread Count 설정 |
| 52 | thread.comm.count=10 | 52 | thread.comm.count=10 |
| @@ -58,7 +58,7 @@ thread.ai.processing.wait.total=3600 | @@ -58,7 +58,7 @@ thread.ai.processing.wait.total=3600 | ||
| 58 | 58 | ||
| 59 | #Python 프로퍼티 설정 | 59 | #Python 프로퍼티 설정 |
| 60 | pytyon.path=D:\\Programs\\devp\\python-3.12.2\\python.exe | 60 | pytyon.path=D:\\Programs\\devp\\python-3.12.2\\python.exe |
| 61 | -python.ai.target=D:\\Working\\Python\\Test1.py | 61 | +python.ai.target=D:\\Working\\Vue\\matching_ai\\src\\test\\resources\\TEST_ALL_V0.3.py |
| 62 | 62 | ||
| 63 | #Auto Matching 제외 | 63 | #Auto Matching 제외 |
| 64 | matching.auto.exceptListByComma=C-A-ROUND(-2) | 64 | matching.auto.exceptListByComma=C-A-ROUND(-2) |
| 65 | \ No newline at end of file | 65 | \ No newline at end of file |