정부지원사업 공고 수집 데몬(gov-scraper) 추가
- government/ Node 데몬: Open API 우선 + HTML 보조 + 디스커버리 전략 - Strategy 패턴 소스 어댑터: KStartupApiSource(공공데이터 Open API), GenericHtmlSource(config 기반) - sundol 3단계 폴백 크롤러(cheerio→Jina→Playwright CDP) Node 재구현, sundol-chrome(9222) 재사용 - Oracle thick 모드(Instant Client + sso 지갑) 접속, gov_source/gov_opportunity 적재(중복제거) - K-Startup 29,017건 + 중기부(mss) 30건 적재 검증, PM2 gov-daemon 등록(60분 주기) - 기업마당(bizinfo)은 자체 crtfcKey 발급 대기 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
60
government/src/db.js
Normal file
60
government/src/db.js
Normal file
@@ -0,0 +1,60 @@
|
||||
// Oracle Autonomous DB 접속 (node-oracledb thick 모드).
|
||||
// Instant Client + sso 지갑(cwallet.sso)을 사용하므로 지갑 비밀번호가 필요 없다.
|
||||
// (백엔드 JDBC 와 동일하게 자동로그인 지갑을 재사용)
|
||||
import oracledb from 'oracledb';
|
||||
import { config } from './config.js';
|
||||
import { log } from './logger.js';
|
||||
|
||||
oracledb.fetchAsString = [oracledb.CLOB];
|
||||
oracledb.autoCommit = false;
|
||||
|
||||
let pool = null;
|
||||
let clientInitialized = false;
|
||||
|
||||
function initClient() {
|
||||
if (clientInitialized) return;
|
||||
oracledb.initOracleClient({
|
||||
libDir: config.oracle.icLibDir,
|
||||
configDir: config.oracle.netConfigDir, // tnsnames.ora + WALLET_LOCATION 보정 sqlnet.ora
|
||||
});
|
||||
clientInitialized = true;
|
||||
}
|
||||
|
||||
export async function initPool() {
|
||||
if (pool) return pool;
|
||||
initClient();
|
||||
pool = await oracledb.createPool({
|
||||
user: config.oracle.user,
|
||||
password: config.oracle.password,
|
||||
connectString: config.oracle.connectString,
|
||||
poolMin: 1,
|
||||
poolMax: 4,
|
||||
poolIncrement: 1,
|
||||
});
|
||||
log.info('Oracle 풀 생성 완료');
|
||||
return pool;
|
||||
}
|
||||
|
||||
export async function withConnection(fn) {
|
||||
if (!pool) await initPool();
|
||||
const conn = await pool.getConnection();
|
||||
try {
|
||||
return await fn(conn);
|
||||
} finally {
|
||||
try {
|
||||
await conn.close();
|
||||
} catch (e) {
|
||||
log.warn('연결 반환 실패:', e.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function closePool() {
|
||||
if (pool) {
|
||||
await pool.close(10);
|
||||
pool = null;
|
||||
log.info('Oracle 풀 종료');
|
||||
}
|
||||
}
|
||||
|
||||
export { oracledb };
|
||||
Reference in New Issue
Block a user