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

[FEATURE] TaskUtil: Add 'force' flag to cleanup task callback #677

Merged
merged 14 commits into from
Nov 15, 2023
7 changes: 4 additions & 3 deletions lib/build/ProjectBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,17 +388,18 @@ class ProjectBuilder {
}));
}

async _executeCleanupTasks() {
async _executeCleanupTasks(force) {
this.#log.info("Executing cleanup tasks...");
await this._buildContext.executeCleanupTasks();

await this._buildContext.executeCleanupTasks(force);
}

_registerCleanupSigHooks() {
const that = this;
function createListener(exitCode) {
return function() {
// Asynchronously cleanup resources, then exit
that._executeCleanupTasks().then(() => {
that._executeCleanupTasks(true).then(() => {
process.exit(exitCode);
});
};
Expand Down
4 changes: 2 additions & 2 deletions lib/build/helpers/BuildContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ class BuildContext {
return projectBuildContext;
}

async executeCleanupTasks() {
async executeCleanupTasks(force) {
await Promise.all(this._projectBuildContexts.map((ctx) => {
return ctx.executeCleanupTasks();
return ctx.executeCleanupTasks(force);
}));
d3xter666 marked this conversation as resolved.
Show resolved Hide resolved
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/build/helpers/ProjectBuildContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ class ProjectBuildContext {
this._queues.cleanup.push(callback);
}

async executeCleanupTasks() {
async executeCleanupTasks(force) {
await Promise.all(this._queues.cleanup.map((callback) => {
return callback();
return callback(force);
}));
}

Expand Down
10 changes: 9 additions & 1 deletion test/lib/build/ProjectBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -727,8 +727,16 @@ test("_executeCleanupTasks", async (t) => {
const executeCleanupTasksStub = sinon.stub(builder._buildContext, "executeCleanupTasks");
await builder._executeCleanupTasks();
t.is(executeCleanupTasksStub.callCount, 1, "BuildContext#executeCleanupTasks got called once");
t.deepEqual(executeCleanupTasksStub.getCall(0).args, [],
t.deepEqual(executeCleanupTasksStub.getCall(0).args, [undefined],
d3xter666 marked this conversation as resolved.
Show resolved Hide resolved
"BuildContext#executeCleanupTasks got called with no arguments");

// reset stub
executeCleanupTasksStub.reset();
// Call with enforcement flag
await builder._executeCleanupTasks(true);
t.is(executeCleanupTasksStub.callCount, 1, "BuildContext#executeCleanupTasks got called once");
t.deepEqual(executeCleanupTasksStub.getCall(0).args, [true],
"BuildContext#executeCleanupTasks got called with force flag");
});

test("instantiate new logger for every ProjectBuilder", async (t) => {
Expand Down