- 템플릿 클론(정규화 후 0줄 상이) → 전 코퍼스 530/530 고유 바디 - 11개 모듈(mg/au/ac/rc/vl/st/py/lg/mm/cm/cl) 각 파일이 distinct한 매입·대사·정산·수수료·지급·원장·마감·마스터·정합성·전문게이트웨이·공통 업무 - TxCore(ATMI 유사) + ECPG(EXEC SQL) 관용구, 프레임워크/헤더/DBIO API/파일ID·경로 유지 - 전체 docker make -j4 = EXIT 0, 958 오브젝트, 데모 바이너리 링크 - inventory.json loc 실측 갱신 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
149 lines
4.2 KiB
Text
149 lines
4.2 KiB
Text
/* @tier easy @module mg @transform msg-gateway-batch */
|
|
/*
|
|
* mg_bt_0002.pgc - 전문게이트웨이 큐 적체 정리 배치 [tier=easy]
|
|
*
|
|
* 접수(R) 상태로 큐(mg_queue)에 등록된 뒤 일정 시간(기본 1800초)을
|
|
* 초과하도록 처리되지 못한 적체 전문을 커서로 순회하며 실패(U)로
|
|
* 만료처리한다. 만료 건수와 최장 적체시간을 집계하여 리포트한다.
|
|
*
|
|
* 실행: mg_bt_0002 <YYYYMMDD> [db@host]
|
|
*/
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include "txcore.h"
|
|
#include "txcore_dbio.h"
|
|
#include "acq_util.h"
|
|
#include "mg_core.h"
|
|
|
|
EXEC SQL INCLUDE sqlca;
|
|
|
|
#define MG_QUEUE_TTL_SEC 1800 /* 큐 적체 만료 임계(초) */
|
|
|
|
/* 적체시간(초)이 임계를 넘었는지 판정 */
|
|
static int mg_is_stale(long elapsed)
|
|
{
|
|
return (elapsed >= MG_QUEUE_TTL_SEC) ? 1 : 0;
|
|
}
|
|
|
|
static int run_mg_bt_0002(const char *biz_date)
|
|
{
|
|
EXEC SQL BEGIN DECLARE SECTION;
|
|
char h_biz_date[9];
|
|
char h_key[16];
|
|
long h_elapsed;
|
|
EXEC SQL END DECLARE SECTION;
|
|
|
|
long total = 0, expired = 0, alive = 0, errcnt = 0;
|
|
long max_wait = 0;
|
|
int rc;
|
|
|
|
memset(h_biz_date, 0, sizeof(h_biz_date));
|
|
strncpy(h_biz_date, biz_date, sizeof(h_biz_date) - 1);
|
|
|
|
EXEC SQL DECLARE cur_mg_bt_0002 CURSOR FOR
|
|
SELECT key, CAST(EXTRACT(EPOCH FROM (now() - enq_ts)) AS bigint)
|
|
FROM mg_queue
|
|
WHERE biz_date = :h_biz_date
|
|
AND status = 'R'
|
|
ORDER BY enq_ts;
|
|
|
|
EXEC SQL OPEN cur_mg_bt_0002;
|
|
if (sqlca.sqlcode != TX_SQL_OK) {
|
|
TX_DBIO_LOG_ERR("OPEN cur_mg_bt_0002");
|
|
return TX_EDB;
|
|
}
|
|
|
|
if (tx_begin() != TX_OK)
|
|
tx_log(TX_LOG_WARN, "[mg_bt_0002] tx_begin 경고");
|
|
|
|
for (;;) {
|
|
EXEC SQL FETCH cur_mg_bt_0002 INTO :h_key, :h_elapsed;
|
|
|
|
if (sqlca.sqlcode == TX_SQL_NOTFOUND)
|
|
break;
|
|
if (sqlca.sqlcode != TX_SQL_OK) {
|
|
TX_DBIO_LOG_ERR("FETCH cur_mg_bt_0002");
|
|
errcnt++;
|
|
break;
|
|
}
|
|
|
|
total++;
|
|
if (h_elapsed > max_wait)
|
|
max_wait = h_elapsed;
|
|
|
|
if (!mg_is_stale(h_elapsed)) {
|
|
alive++;
|
|
continue;
|
|
}
|
|
|
|
rc = mg_rec_update_status(h_key, MG_ST_FAIL);
|
|
if (rc != TX_OK) {
|
|
tx_log(TX_LOG_ERROR, "[mg_bt_0002] 만료처리 실패 key=%s rc=%d", h_key, rc);
|
|
errcnt++;
|
|
} else {
|
|
expired++;
|
|
tx_log(TX_LOG_DEBUG, "[mg_bt_0002] 적체만료 key=%s wait=%lds", h_key, h_elapsed);
|
|
}
|
|
}
|
|
|
|
EXEC SQL CLOSE cur_mg_bt_0002;
|
|
|
|
if (errcnt == 0)
|
|
tx_commit();
|
|
else
|
|
tx_abort();
|
|
|
|
tx_log(TX_LOG_INFO,
|
|
"[mg_bt_0002] 요약 date=%s 대상=%ld 만료=%ld 유지=%ld 오류=%ld",
|
|
biz_date, total, expired, alive, errcnt);
|
|
|
|
printf("========== 큐 적체 정리 배치 [mg_bt_0002] ==========\n");
|
|
printf(" 영업일 : %s\n", biz_date);
|
|
printf(" 적체 임계(초) : %d\n", MG_QUEUE_TTL_SEC);
|
|
printf(" 점검 건수 : %ld\n", total);
|
|
printf(" 만료처리(U) : %ld\n", expired);
|
|
printf(" 유지 건수 : %ld\n", alive);
|
|
printf(" 최장 적체(초) : %ld\n", max_wait);
|
|
printf(" 오류 건수 : %ld\n", errcnt);
|
|
printf("=============================================\n");
|
|
|
|
return (errcnt == 0) ? TX_OK : TX_FAIL;
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
const char *biz_date;
|
|
const char *target;
|
|
int rc;
|
|
|
|
tx_set_loglevel(TX_LOG_INFO);
|
|
|
|
if (argc < 2) {
|
|
fprintf(stderr, "사용법: %s <YYYYMMDD> [db@host]\n", argv[0]);
|
|
return 2;
|
|
}
|
|
biz_date = argv[1];
|
|
target = (argc >= 3) ? argv[2] : NULL;
|
|
|
|
if (!date_is_valid(biz_date)) {
|
|
fprintf(stderr, "오류: 유효하지 않은 영업일 '%s'\n", biz_date);
|
|
return 2;
|
|
}
|
|
|
|
tx_log(TX_LOG_INFO, "[mg_bt_0002] 큐 적체 정리 시작 date=%s", biz_date);
|
|
|
|
rc = mg_dbio_connect(target);
|
|
if (rc != TX_OK) {
|
|
tx_log(TX_LOG_ERROR, "[mg_bt_0002] DB 접속 실패 rc=%d", rc);
|
|
return 1;
|
|
}
|
|
|
|
rc = run_mg_bt_0002(biz_date);
|
|
|
|
mg_dbio_disconnect();
|
|
|
|
tx_log(TX_LOG_INFO, "[mg_bt_0002] 배치 종료 rc=%d(%s)", rc, tx_strerror(rc));
|
|
return (rc == TX_OK) ? 0 : 1;
|
|
}
|