- dbio io(289): fetch/touch/total 시그니처 유지, SQL 바디를 JOIN/집계/커서/ upsert/DELETE 등 구조로 고유화 → 289/289 고유 - common cu(120): 유틸 시그니처 유지, Luhn/CRC/Zeller/BIN레인지/amortization/ netting 등 실 알고리즘으로 고유화 → 120/120 고유 - 심화: 실제 EXEC SQL 없던 프로그램에 SELECT/INSERT/UPDATE/커서+tx 추가 → online+batch 530/530 전부 실제 SQL 보유 - 전 코퍼스 프로그램 939/939 고유, 전체 docker make -j4 = EXIT 0, 958 오브젝트 - 임시 생성기 제거, inventory.json loc 실측 갱신 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
124 lines
4 KiB
Text
124 lines
4 KiB
Text
/* @tier medium @module mg @transform msg-gateway-online */
|
|
/*
|
|
* mg_ol_0024.pgc - 전문게이트웨이 전문 타임아웃 판정 서비스 (MG_OL_0024) [tier=medium]
|
|
*
|
|
* 전문 송신시각(SENDTIME)과 현재시각(NOWTIME)의 차이를 밀리초로 환산하여
|
|
* 임계값(기본 5000ms) 초과 여부로 타임아웃을 판정한다. 자정 경과(day-wrap)
|
|
* 를 보정하며, 판정결과(TIMEOUT)와 경과시간(ELAPSEDMS)을 응답한다.
|
|
* (순수 계산 로직 - DB 접근 없음)
|
|
*/
|
|
#include <stdio.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_TIMEOUT_DEFAULT_MS 5000L
|
|
#define MG_MS_PER_DAY 86400000L
|
|
|
|
/* HHMMSS 6자리를 자정기준 밀리초로 환산 (형식오류 시 -1) */
|
|
static long hhmmss_to_ms(const char *s)
|
|
{
|
|
int i, h, m, sec;
|
|
|
|
if (s == NULL || strlen(s) < 6)
|
|
return -1;
|
|
for (i = 0; i < 6; i++) {
|
|
if (s[i] < '0' || s[i] > '9')
|
|
return -1;
|
|
}
|
|
h = (s[0] - '0') * 10 + (s[1] - '0');
|
|
m = (s[2] - '0') * 10 + (s[3] - '0');
|
|
sec = (s[4] - '0') * 10 + (s[5] - '0');
|
|
if (h > 23 || m > 59 || sec > 59)
|
|
return -1;
|
|
return ((long)h * 3600L + (long)m * 60L + (long)sec) * 1000L;
|
|
}
|
|
|
|
TX_SERVICE(MG_OL_0024, ctx)
|
|
{
|
|
char sendtime[16], nowtime[16];
|
|
long threshold = MG_TIMEOUT_DEFAULT_MS;
|
|
long send_ms, now_ms, elapsed;
|
|
int is_timeout;
|
|
|
|
tx_log(TX_LOG_INFO, "[MG_OL_0024] 전문 타임아웃 판정 서비스 진입");
|
|
|
|
/* 1) 송신시각/현재시각 수신 (HHMMSS) */
|
|
if (tx_buf_get(ctx->in, "SENDTIME", sendtime, sizeof(sendtime)) != TX_OK ||
|
|
tx_buf_get(ctx->in, "NOWTIME", nowtime, sizeof(nowtime)) != TX_OK) {
|
|
tx_log(TX_LOG_ERROR, "[MG_OL_0024] 시각 필드(SENDTIME/NOWTIME) 누락");
|
|
tx_return(ctx, TX_EINVAL, ctx->out);
|
|
return;
|
|
}
|
|
|
|
/* 임계값은 선택 입력 (미제출 시 기본값) */
|
|
tx_buf_getlong(ctx->in, "THRESHMS", &threshold);
|
|
if (threshold <= 0)
|
|
threshold = MG_TIMEOUT_DEFAULT_MS;
|
|
|
|
/* 2) 시각 파싱 */
|
|
send_ms = hhmmss_to_ms(sendtime);
|
|
now_ms = hhmmss_to_ms(nowtime);
|
|
if (send_ms < 0 || now_ms < 0) {
|
|
tx_log(TX_LOG_WARN, "[MG_OL_0024] 시각 형식 오류 send=%s now=%s",
|
|
sendtime, nowtime);
|
|
tx_buf_reset(ctx->out);
|
|
tx_buf_sets(ctx->out, "RESP", RESP_INVALID);
|
|
tx_return(ctx, TX_EINVAL, ctx->out);
|
|
return;
|
|
}
|
|
|
|
/* 3) 경과시간 계산 (자정 경과 보정) */
|
|
elapsed = now_ms - send_ms;
|
|
if (elapsed < 0)
|
|
elapsed += MG_MS_PER_DAY;
|
|
|
|
is_timeout = (elapsed > threshold);
|
|
|
|
/* 4) 판정결과 응답 */
|
|
tx_buf_reset(ctx->out);
|
|
tx_buf_sets(ctx->out, "RESP", RESP_OK);
|
|
tx_buf_setlong(ctx->out, "ELAPSEDMS", elapsed);
|
|
tx_buf_setlong(ctx->out, "THRESHMS", threshold);
|
|
tx_buf_sets(ctx->out, "TIMEOUT", is_timeout ? "Y" : "N");
|
|
|
|
if (is_timeout)
|
|
tx_log(TX_LOG_WARN, "[MG_OL_0024] 타임아웃 판정 경과=%ldms 임계=%ldms",
|
|
elapsed, threshold);
|
|
else
|
|
tx_log(TX_LOG_INFO, "[MG_OL_0024] 정상 경과=%ldms 임계=%ldms",
|
|
elapsed, threshold);
|
|
|
|
/* 타임아웃 판정 이력(mg_timeout_log)을 임베디드 SQL 로 적재 */
|
|
{
|
|
EXEC SQL BEGIN DECLARE SECTION;
|
|
long h_to_elapsed;
|
|
long h_to_thresh;
|
|
char h_to_flag[2];
|
|
EXEC SQL END DECLARE SECTION;
|
|
|
|
h_to_elapsed = elapsed;
|
|
h_to_thresh = threshold;
|
|
h_to_flag[0] = is_timeout ? 'Y' : 'N';
|
|
h_to_flag[1] = '\0';
|
|
|
|
if (tx_begin() == TX_OK) {
|
|
EXEC SQL INSERT INTO mg_timeout_log
|
|
(elapsed_ms, thresh_ms, timeout_yn)
|
|
VALUES (:h_to_elapsed, :h_to_thresh, :h_to_flag);
|
|
if (sqlca.sqlcode != TX_SQL_OK) {
|
|
TX_DBIO_LOG_ERR("INSERT mg_timeout_log");
|
|
tx_abort();
|
|
} else {
|
|
tx_commit();
|
|
}
|
|
}
|
|
}
|
|
|
|
tx_return(ctx, TX_OK, ctx->out);
|
|
}
|