Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit tests to remaining sync related controllers #212

Merged
merged 5 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ function cleanup() {

clearInterval(probeId);
clearInterval(queueId);
queueManager.close(dataConnection.close(process.exit));
queueManager.close(() => setTimeout(() => {
dataConnection.close(process.exit);
}, 3000));
}

/**
Expand Down Expand Up @@ -242,15 +244,14 @@ function notReadyHandler() {

/**
* @function shutdown
* Shuts down this application after at least 3 seconds.
* Begins the shutdown procedure for this application
*/
function shutdown() {
log.info('Shutting down', { function: 'shutdown' });
// Wait 3 seconds before starting cleanup
if (!state.shutdown) {
state.shutdown = true;
log.info('Application no longer accepting traffic', { function: 'shutdown' });
setTimeout(cleanup, 3000);
cleanup();
}
}

Expand Down
27 changes: 20 additions & 7 deletions app/src/components/queueManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class QueueManager {
*/
constructor() {
if (!QueueManager._instance) {
this._isBusy = false;
this.isBusy = false;
this._toClose = false;
QueueManager._instance = this;
}
Expand All @@ -29,6 +29,19 @@ class QueueManager {
return this._isBusy;
}

/**
* @function isBusy
* @param {boolean} v The new state
* Sets the isBusy state
*/
set isBusy(v) {
this._isBusy = v;
if (!v && this.toClose) {
log.info('No longer processing jobs', { function: 'isBusy' });
if (this._cb) this._cb();
}
}

/**
* @function toClose
* Gets the toClose state
Expand All @@ -53,13 +66,13 @@ class QueueManager {

/**
* @function close
* Spinlock until any remaining jobs are completed
* Stalls the callback until any remaining jobs are completed
* @param {function} [cb] Optional callback
*/
close(cb = undefined) {
this._toClose = true;
if (this.isBusy) setTimeout(this.close(cb), 250);
else {
this._cb = cb;
if (!this.isBusy) {
log.info('No longer processing jobs', { function: 'close' });
if (cb) cb();
}
Expand All @@ -77,16 +90,16 @@ class QueueManager {
const response = await objectQueueService.dequeue();

if (response.length) {
this.isBusy = true;
job = response[0];
this._isBusy = true;

log.verbose(`Started processing job id ${job.id}`, { function: 'processNextJob', job: job });

const objectId = await syncService.syncJob(job.path, job.bucketId, job.full, job.createdBy);

this._isBusy = false;
log.verbose(`Finished processing job id ${job.id}`, { function: 'processNextJob', job: job, objectId: objectId });

this.isBusy = false;
// If job is completed, check if there are more jobs
if (!this.toClose) this.checkQueue();
}
Expand All @@ -109,7 +122,7 @@ class QueueManager {
});
}

this._isBusy = false;
this.isBusy = false;
}
}
}
Expand Down
Loading