@@ -26,7 +26,10 @@ const logger = createLogger('worker-runner')
2626const INVALID = { __invalid : true } as const
2727type CellValue = string | typeof INVALID
2828
29- // 컬럼별 스트림 생성 함수
29+ /**
30+ * 컬럼 설정에 따라 데이터 생성 스트림을 반환
31+ * (FAKER, AI, FILE, FIXED, REFERENCE)
32+ */
3033function createColumnStream (
3134 col : {
3235 columnName : string
@@ -146,7 +149,9 @@ function createColumnStream(
146149 }
147150}
148151
149- // AI 컬럼과 non-AI 컬럼 분리
152+ /**
153+ * 컬럼 목록을 AI / non-AI 인덱스로 분리
154+ */
150155function separateColumnsByType ( columns : { dataSource : DataSourceType } [ ] ) : {
151156 aiColumns : number [ ]
152157 nonAiColumns : number [ ]
@@ -280,6 +285,9 @@ type DirectContext = {
280285 close : ( ) => Promise < void >
281286}
282287
288+ /**
289+ * DIRECT_DB 모드에서 사용할 DB 연결 컨텍스트 생성
290+ */
283291async function createDirectContext (
284292 dbType : keyof typeof DBMS_MAP ,
285293 connection : NonNullable < WorkerTask [ 'connection' ] >
@@ -322,6 +330,12 @@ async function createDirectContext(
322330 }
323331}
324332
333+ /**
334+ * 테이블 단위 데이터 생성 Worker
335+ * - 컬럼 스트림 생성
336+ * - 행 조립
337+ * - SQL 파일 생성 또는 DB 삽입
338+ */
325339async function runWorker ( task : WorkerTask ) : Promise < WorkerResult > {
326340 const { table, dbType, mode, connection } = task
327341 const { tableName, recordCnt, columns } = table
@@ -347,7 +361,6 @@ async function runWorker(task: WorkerTask): Promise<WorkerResult> {
347361 }
348362
349363 logger . info ( `[${ tableName } ] 시작: ${ recordCnt . toLocaleString ( ) } 행, ${ columns . length } 컬럼` )
350- const startTime = Date . now ( )
351364 let totalProcessed = 0
352365 const numChunks = Math . max ( 1 , Math . ceil ( recordCnt / CHUNK_SIZE ) )
353366
@@ -359,22 +372,16 @@ async function runWorker(task: WorkerTask): Promise<WorkerResult> {
359372 continue
360373 }
361374
362- logger . info ( `\n[${ tableName } ] 청크 ${ chunkIdx + 1 } /${ numChunks } 처리 중 (${ chunkSize } 행)` )
363- const chunkStartTime = Date . now ( )
364-
365375 const columnStreams = columns . map ( ( col ) => createColumnStream ( col , task , chunkSize ) )
366376 const { aiColumns, nonAiColumns } = separateColumnsByType ( columns )
367377 const chunkColumnValues : ( string | typeof INVALID ) [ ] [ ] = new Array ( columns . length )
368378
369379 // === Non-AI 컬럼 처리 (예외 처리 일관화) ===
370380 if ( nonAiColumns . length > 0 ) {
371- logger . info ( `[${ tableName } ] Non-AI 컬럼 동시 처리:` )
372381 const nonAiResults = await Promise . all (
373382 nonAiColumns . map ( async ( colIdx ) => {
374383 const col = columns [ colIdx ]
375384 const stream = columnStreams [ colIdx ]
376- const colStart = Date . now ( )
377- logger . info ( ` ▶ [${ col . columnName } ] 처리 (${ col . dataSource } )` )
378385
379386 const values : ( string | typeof INVALID ) [ ] = [ ]
380387 for ( let i = 0 ; i < chunkSize ; i ++ ) {
@@ -394,9 +401,6 @@ async function runWorker(task: WorkerTask): Promise<WorkerResult> {
394401 }
395402 }
396403
397- const colDuration = ( ( Date . now ( ) - colStart ) / 1000 ) . toFixed ( 2 )
398- logger . info ( ` ✓ [${ col . columnName } ] 완료 (${ colDuration } 초)` )
399-
400404 return { colIdx, values }
401405 } )
402406 )
@@ -408,17 +412,13 @@ async function runWorker(task: WorkerTask): Promise<WorkerResult> {
408412
409413 // === AI 컬럼 처리 (동시 MAX_AI_CONCURRENT개, 예외 처리 통일) ===
410414 if ( aiColumns . length > 0 ) {
411- logger . info ( `[${ tableName } ] AI 컬럼 처리 (동시 ${ MAX_AI_CONCURRENT } 개):` )
412-
413415 for ( let i = 0 ; i < aiColumns . length ; i += MAX_AI_CONCURRENT ) {
414416 const batch = aiColumns . slice ( i , i + MAX_AI_CONCURRENT )
415417
416418 const batchResults = await Promise . all (
417419 batch . map ( async ( colIdx ) => {
418420 const col = columns [ colIdx ]
419421 const stream = columnStreams [ colIdx ]
420- const colStart = Date . now ( )
421- logger . info ( ` ▶ [${ col . columnName } ] 처리 (${ col . dataSource } )` )
422422
423423 const values : ( string | typeof INVALID ) [ ] = [ ]
424424 for ( let j = 0 ; j < chunkSize ; j ++ ) {
@@ -438,9 +438,6 @@ async function runWorker(task: WorkerTask): Promise<WorkerResult> {
438438 }
439439 }
440440
441- const colDuration = ( ( Date . now ( ) - colStart ) / 1000 ) . toFixed ( 2 )
442- logger . info ( ` ✓ [${ col . columnName } ] 완료 (${ colDuration } 초)` )
443-
444441 return { colIdx, values }
445442 } )
446443 )
@@ -450,7 +447,6 @@ async function runWorker(task: WorkerTask): Promise<WorkerResult> {
450447 } )
451448
452449 if ( i + MAX_AI_CONCURRENT < aiColumns . length ) {
453- logger . info ( ` … 다음 AI 컬럼 대기 (1초)...` )
454450 await new Promise ( ( res ) => setTimeout ( res , 1000 ) )
455451 }
456452 }
@@ -477,13 +473,11 @@ async function runWorker(task: WorkerTask): Promise<WorkerResult> {
477473 `[행 변환 오류] ${ tableName } ${ totalProcessed + rowIdx + 1 } 행 변환 실패`
478474 )
479475 }
476+ } else if ( ! directMode ) {
477+ totalProcessed ++
480478 }
481479
482480 rows . push ( `(${ rowValues . join ( ', ' ) } )` )
483-
484- if ( ! directMode ) {
485- totalProcessed ++
486- }
487481 }
488482
489483 // === DIRECT_DB bulk insert + fallback ===
@@ -529,47 +523,18 @@ async function runWorker(task: WorkerTask): Promise<WorkerResult> {
529523 totalProcessed += successOnThisChunk // 성공한 row만 증가
530524 totalFailed += failedOnThisChunk // fallback에서 실패한 row
531525
532- process . parentPort . postMessage ( {
533- type : 'row-delta' ,
534- tableName,
535- success : successOnThisChunk ,
536- fail : failedOnThisChunk
537- } )
538-
539526 await fs . promises . appendFile ( sqlPath , bulkSQL + '\n' , 'utf8' )
540527 }
541528
542- const chunkDuration = ( ( Date . now ( ) - chunkStartTime ) / 1000 ) . toFixed ( 2 )
543- logger . info ( `\n[${ tableName } ] 청크 ${ chunkIdx + 1 } 완료 (${ chunkDuration } 초)` )
544-
545- const progressPercent =
546- chunkIdx + 1 === numChunks ? 100 : Math . floor ( ( chunkEnd / recordCnt ) * 100 )
547-
548529 process . parentPort . postMessage ( {
549530 type : 'row-progress' ,
550531 tableName,
551- progress : progressPercent
532+ progress : chunkSize
552533 } )
553534
554535 await new Promise ( ( res ) => setTimeout ( res , 100 ) )
555-
556- if ( chunkEnd === recordCnt ) {
557- columns . forEach ( ( col ) => {
558- process . parentPort . postMessage ( {
559- type : 'column-progress' ,
560- tableName,
561- columnName : col . columnName ,
562- progress : 100
563- } )
564- } )
565- }
566536 }
567537
568- const totalDuration = ( ( Date . now ( ) - startTime ) / 1000 ) . toFixed ( 2 )
569- logger . info (
570- `\n[${ tableName } ] 전체 완료 (${ totalDuration } 초, ${ totalProcessed . toLocaleString ( ) } 행)`
571- )
572-
573538 if ( directContext ) {
574539 await directContext . commit ( )
575540 await directContext . close ( )
0 commit comments