Docker 파일

This commit is contained in:
2025-12-28 14:10:35 +09:00
parent 9d2a6638b5
commit ba7a208da9
3 changed files with 4 additions and 118 deletions

View File

@@ -1,18 +1,15 @@
import { initPrivnetTables, shouldAutoStartScheduler } from '../utils/db'
import { shouldAutoStartScheduler } from '../utils/db'
import { privnetScheduler } from '../utils/privnet-scheduler'
export default defineNitroPlugin(async (nitroApp) => {
console.log('[Plugin] privnet-init starting...')
// DB 테이블 초기화
await initPrivnetTables()
// 스케줄러 자동 시작 (환경에 따라)
if (shouldAutoStartScheduler()) {
privnetScheduler.start()
console.log('[Plugin] privnet scheduler auto-started (production mode)')
} else {
console.log('[Plugin] privnet scheduler NOT started (development mode - use API to start)')
console.log('[Plugin] privnet scheduler NOT started (development mode)')
}
// 서버 종료 시 클린업

View File

@@ -1,18 +1,15 @@
import { initPubnetTables, shouldAutoStartScheduler } from '../utils/db'
import { shouldAutoStartScheduler } from '../utils/db'
import { pubnetScheduler } from '../utils/pubnet-scheduler'
export default defineNitroPlugin(async (nitroApp) => {
console.log('[Plugin] pubnet-init starting...')
// DB 테이블 초기화
await initPubnetTables()
// 스케줄러 자동 시작 (환경에 따라)
if (shouldAutoStartScheduler()) {
pubnetScheduler.start()
console.log('[Plugin] pubnet scheduler auto-started (production mode)')
} else {
console.log('[Plugin] pubnet scheduler NOT started (development mode - use API to start)')
console.log('[Plugin] pubnet scheduler NOT started (development mode)')
}
// 서버 종료 시 클린업

View File

@@ -63,121 +63,13 @@ export async function execute(sql: string, params?: any[]): Promise<number> {
* 스케줄러 자동시작 여부
*/
export function shouldAutoStartScheduler(): boolean {
// 환경변수로 명시적 설정된 경우
const envValue = process.env.AUTO_START_SCHEDULER
if (envValue !== undefined) {
return envValue === 'true'
}
// 기본값: production=true, development=false
return !isDev
}
/**
* pubnet 테이블 초기화 (PostgreSQL용)
*/
export async function initPubnetTables(): Promise<void> {
const pool = getPool()
// pubnet_targets
await pool.query(`
CREATE TABLE IF NOT EXISTS pubnet_targets (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL,
url TEXT NOT NULL UNIQUE,
is_active INTEGER DEFAULT 1,
sort_order INTEGER DEFAULT 0,
created_at TEXT DEFAULT to_char(NOW(), 'YYYY-MM-DD HH24:MI:SS'),
updated_at TEXT DEFAULT to_char(NOW(), 'YYYY-MM-DD HH24:MI:SS')
)
`)
// pubnet_logs
await pool.query(`
CREATE TABLE IF NOT EXISTS pubnet_logs (
id SERIAL PRIMARY KEY,
target_id INTEGER NOT NULL,
is_success INTEGER NOT NULL,
checked_at TEXT DEFAULT to_char(NOW(), 'YYYY-MM-DD HH24:MI:SS'),
FOREIGN KEY (target_id) REFERENCES pubnet_targets(id)
)
`)
// pubnet_status (싱글톤 패턴)
await pool.query(`
CREATE TABLE IF NOT EXISTS pubnet_status (
id INTEGER PRIMARY KEY CHECK (id = 1),
current_index INTEGER DEFAULT 0,
check_interval INTEGER DEFAULT 300000,
is_healthy INTEGER DEFAULT 1,
last_target_id INTEGER,
last_checked_at TEXT,
scheduler_running INTEGER DEFAULT 0,
updated_at TEXT DEFAULT to_char(NOW(), 'YYYY-MM-DD HH24:MI:SS')
)
`)
// 상태 행 존재 확인 및 생성
const statusExists = await queryOne<{ cnt: number }>('SELECT COUNT(*) as cnt FROM pubnet_status')
if (!statusExists || statusExists.cnt === 0) {
await pool.query('INSERT INTO pubnet_status (id) VALUES (1)')
}
console.log('[DB] pubnet tables initialized')
}
/**
* privnet 테이블 초기화 (PostgreSQL용)
*/
export async function initPrivnetTables(): Promise<void> {
const pool = getPool()
// privnet_targets
await pool.query(`
CREATE TABLE IF NOT EXISTS privnet_targets (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL,
url TEXT NOT NULL UNIQUE,
is_active INTEGER DEFAULT 1,
sort_order INTEGER DEFAULT 0,
created_at TEXT DEFAULT to_char(NOW(), 'YYYY-MM-DD HH24:MI:SS'),
updated_at TEXT DEFAULT to_char(NOW(), 'YYYY-MM-DD HH24:MI:SS')
)
`)
// privnet_logs
await pool.query(`
CREATE TABLE IF NOT EXISTS privnet_logs (
id SERIAL PRIMARY KEY,
target_id INTEGER NOT NULL,
is_success INTEGER NOT NULL,
checked_at TEXT DEFAULT to_char(NOW(), 'YYYY-MM-DD HH24:MI:SS'),
FOREIGN KEY (target_id) REFERENCES privnet_targets(id)
)
`)
// privnet_status (싱글톤 패턴)
await pool.query(`
CREATE TABLE IF NOT EXISTS privnet_status (
id INTEGER PRIMARY KEY CHECK (id = 1),
current_index INTEGER DEFAULT 0,
check_interval INTEGER DEFAULT 300000,
is_healthy INTEGER DEFAULT 1,
last_target_id INTEGER,
last_checked_at TEXT,
scheduler_running INTEGER DEFAULT 0,
updated_at TEXT DEFAULT to_char(NOW(), 'YYYY-MM-DD HH24:MI:SS')
)
`)
// 상태 행 존재 확인 및 생성
const statusExists = await queryOne<{ cnt: number }>('SELECT COUNT(*) as cnt FROM privnet_status')
if (!statusExists || statusExists.cnt === 0) {
await pool.query('INSERT INTO privnet_status (id) VALUES (1)')
}
console.log('[DB] privnet tables initialized')
}
/**
* 연결 풀 종료
*/