import { Client } from '@elastic/elasticsearch' ; import { workerData } from 'worker_threads' ; import { getScenario } from './get_scenario' ; import { createLogger , LogLevel } from '../../lib/utils/create_logger' ; import { uploadEvents } from './upload_events' ; export interface WorkerData { bucketFrom : number ; bucketTo : number ; file : string ; scenarioOpts : Record < string , any > | undefined ; logLevel : LogLevel ; clientWorkers : number ; batchSize : number ; intervalInMs : number ; bucketSizeInMs : number ; target : string ; workers : number ; writeTarget ? : string ; } const { bucketFrom , bucketTo , file , logLevel , clientWorkers , batchSize , intervalInMs , bucketSizeInMs , workers , target , writeTarget , scenarioOpts , } = workerData as WorkerData ; async function uploadNextBatch ( ) { if ( bucketFrom === bucketTo ) { return ; } const logger = createLogger ( logLevel ) ; const client = new Client ( { node : target , } ) ; const scenario = await logger . perf ( 'get_scenario' , ( ) => getScenario ( { file , logger } ) ) ; const { generate } = await scenario ( { intervalInMs , bucketSizeInMs , logLevel , file , clientWorkers , batchSize , target , workers , writeTarget , scenarioOpts , } ) ; const events = logger . perf ( 'execute_scenario' , ( ) => generate ( { from : bucketFrom , to : bucketTo } ) ) ; return uploadEvents ( { events , client , clientWorkers , batchSize , logger , } ) ; } uploadNextBatch ( ) . then ( ( ) => { process . exit ( 0 ) ; } ) . catch ( ( error ) => { console . log ( error ) ; setTimeout ( ( ) => { process . exit ( 1 ) ; } , 100 ) ; } ) ;