File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ const dotenv = require ( 'dotenv' ) ;
2+ dotenv . config ( { path : require ( 'path' ) . join ( __dirname , '../../.env' ) } ) ;
3+
4+ const { validateEnv } = require ( '@urbackend/common' ) ;
5+
6+ if ( process . env . NODE_ENV !== 'test' ) {
7+ validateEnv ( ) ;
8+ }
9+
10+ const { initExportWorker } = require ( './src/workers/export.worker' ) ;
11+
12+ const { connectDB } = require ( '@urbackend/common' ) ;
13+
14+ ( async ( ) => {
15+ try {
16+ await connectDB ( ) ;
17+
18+ const worker = initExportWorker ( ) ;
19+
20+ console . log ( '[CONSUMER] Export worker started and listening for jobs...' ) ;
21+
22+ const shutdown = async ( ) => {
23+ console . log ( 'Shutting down worker...' ) ;
24+ await worker . close ( ) ;
25+ process . exit ( 0 ) ;
26+ } ;
27+
28+ process . on ( 'SIGINT' , shutdown ) ;
29+ process . on ( 'SIGTERM' , shutdown ) ;
30+
31+ } catch ( err ) {
32+ console . error ( 'Failed to start worker:' , err ) ;
33+ process . exit ( 1 ) ;
34+ }
35+ } ) ( ) ;
Original file line number Diff line number Diff line change 44 "description" : " " ,
55 "main" : " src/app.js" ,
66 "scripts" : {
7- "dev" : " node src/exportWorker .js" ,
8- "start" : " node src/exportWorker .js" ,
7+ "dev" : " node index .js" ,
8+ "start" : " node index .js" ,
99 "test" : " jest --testPathPatterns=src/"
1010 },
1111 "keywords" : [],
Original file line number Diff line number Diff line change 1- const dotenv = require ( 'dotenv' ) ;
2- dotenv . config ( { path : require ( 'path' ) . join ( __dirname , '../../../.env' ) } ) ;
3-
41const { Worker } = require ( 'bullmq' ) ;
5- const mongoose = require ( 'mongoose' )
62const fs = require ( 'fs' ) ;
73const path = require ( 'path' ) ;
84const os = require ( 'os' ) ;
5+
96const {
107 redis,
118 exportQueue,
@@ -17,12 +14,6 @@ const {
1714 getBucket
1815} = require ( '@urbackend/common' ) ;
1916
20- const { validateEnv } = require ( '@urbackend/common' ) ;
21-
22- if ( process . env . NODE_ENV !== 'test' ) {
23- validateEnv ( ) ;
24- }
25-
2617const initExportWorker = ( ) => {
2718 const worker = new Worker ( exportQueue . name , async ( job ) => {
2819 const { projectId, userId, email } = job . data ;
@@ -109,21 +100,4 @@ const initExportWorker = () => {
109100 return worker ;
110101} ;
111102
112- if ( require . main === module ) {
113-
114- const { connectDB } = require ( '@urbackend/common' ) ;
115-
116- ( async ( ) => {
117- try {
118- await connectDB ( ) ;
119-
120- initExportWorker ( ) ;
121-
122- console . log ( '[CONSUMER] Export worker started and listening for jobs...' ) ;
123- } catch ( err ) {
124- console . error ( 'Failed to start worker:' , err ) ;
125- process . exit ( 1 ) ;
126- }
127- } ) ( ) ;
128- }
129103module . exports = { initExportWorker } ;
You can’t perform that action at this time.
0 commit comments