This repository was archived by the owner on Aug 6, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 6 files changed +53
-6
lines changed
Expand file tree Collapse file tree 6 files changed +53
-6
lines changed Original file line number Diff line number Diff line change 2727 sudo docker stop $(sudo docker ps -a -q)
2828 sudo sh rundocker.sh
2929 sudo sh rundocker.sh
30+ sudo docker container prune -f
3031 '
3132
Original file line number Diff line number Diff line change @@ -72,4 +72,4 @@ RUN mkdir repos && chmod 755 repos
7272
7373# entry to kick-off the worker
7474EXPOSE 3000
75- CMD ["npm " , "start " ]
75+ CMD ["node " , "index.js " ]
Original file line number Diff line number Diff line change @@ -263,6 +263,32 @@ describe('Mongo Tests', () => {
263263 await mongo . logMessageInMongo ( job2 , 'message 1' ) ;
264264 } , 5000 ) ;
265265
266+ /** ******************************************************************
267+ * resetJobForReenqueue() *
268+ ******************************************************************* */
269+ it ( 'resetJobForReenqueue(queueCollection, job) works properly' , async ( ) => {
270+ const jobsColl = db . collection ( 'jobs' ) ;
271+
272+ await mongo . resetJobForReenqueue ( jobsColl , job2 ) ;
273+ const currJob = await jobsColl . findOne ( { _id : job2 . _id } ) ;
274+ expect ( currJob ) . toBeTruthy ( ) ;
275+ expect ( currJob . status ) . toEqual ( 'inQueue' ) ;
276+ expect ( currJob . startTime ) . toBeNull ( ) ;
277+ expect ( currJob . logs [ 0 ] ) . toEqual ( 'Job restarted due to server shutdown.' ) ;
278+ } , 5000 ) ;
279+
280+ it ( 'resetJobForReenqueue() fails on incorrect jobId' , async ( ) => {
281+ const jobsColl = db . collection ( 'jobs' ) ;
282+ expect . assertions ( 1 ) ;
283+ await expect (
284+ mongo . resetJobForReenqueue (
285+ jobsColl ,
286+ { _id : 'notRealId' , numFailures : 0 } ,
287+ 'a'
288+ )
289+ ) . rejects . toBeTruthy ( ) ;
290+ } , 5000 ) ;
291+
266292 /** ******************************************************************
267293 * reportStatus() *
268294 ******************************************************************* */
Original file line number Diff line number Diff line change @@ -36,10 +36,10 @@ describe('Test Class', () => {
3636 it ( 'onSignal()' , async ( ) => {
3737 worker . setCurrentJob ( { job : 'doesnt matter' } ) ;
3838 workerUtils . promiseTimeoutS = jest . fn ( ) . mockResolvedValue ( ) ;
39- mongo . finishJobWithFailure = jest . fn ( ) . mockResolvedValue ( ) ;
39+ mongo . resetJobForReenqueue = jest . fn ( ) . mockResolvedValue ( ) ;
4040
4141 await expect ( worker . gracefulShutdown ( ) ) . resolves . toBeUndefined ( ) ;
42- expect ( mongo . finishJobWithFailure ) . toHaveBeenCalledTimes ( 1 ) ;
42+ expect ( mongo . resetJobForReenqueue ) . toHaveBeenCalledTimes ( 1 ) ;
4343
4444 worker . setCurrentJob ( null ) ;
4545 } ) ;
Original file line number Diff line number Diff line change @@ -130,6 +130,26 @@ module.exports = {
130130 }
131131 } ,
132132
133+ // Updates the status to be inQueue
134+ async resetJobForReenqueue ( queueCollection , job ) {
135+ const query = { _id : job . _id } ;
136+ const reenqueueMessage = 'Job restarted due to server shutdown.' ;
137+
138+ const update = {
139+ $set : {
140+ startTime : null ,
141+ status : 'inQueue' ,
142+ error : { } ,
143+ logs : [ reenqueueMessage ] ,
144+ }
145+ } ;
146+
147+ const updateResult = await queueCollection . updateOne ( query , update ) ;
148+ if ( updateResult . result . n < 1 ) {
149+ throw new Error ( `Failed to update job (${ job . _id } ) in queue during re-enqueue operation` ) ;
150+ }
151+ } ,
152+
133153 async updateJobWithPurgedURLs ( currentJob , urlArray ) {
134154 const queueCollection = module . exports . getCollection ( ) ;
135155 if ( queueCollection ) {
Original file line number Diff line number Diff line change @@ -96,17 +96,17 @@ module.exports = {
9696 workerUtils . resetDirectory ( 'work/' ) ;
9797 await workerUtils . promiseTimeoutS (
9898 MONGO_TIMEOUT_S ,
99- await mongo . finishJobWithFailure (
99+ await mongo . resetJobForReenqueue (
100100 queueCollection ,
101101 currentJob ,
102- 'Server is being shutdown'
103102 ) ,
104- `Mongo Timeout Error: Timed out finishing failed job with jobId: ${ currentJob . _id } `
103+ `Mongo Timeout Error: Timed out finishing re-enqueueing job with jobId: ${ currentJob . _id } `
105104 ) ;
106105 }
107106 if ( mongoClient ) {
108107 monitorInstance . reportStatus ( 'closed connection' ) ;
109108 mongoClient . close ( ) ;
109+ console . log ( '\nServer has closed mongo client connection' ) ;
110110 }
111111 } ,
112112
You can’t perform that action at this time.
0 commit comments