Skip to content

Commit

Permalink
cicd fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-fabian committed Jul 8, 2024
1 parent bf49939 commit c5def66
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
14 changes: 12 additions & 2 deletions src/__tests__/thread-job.service.heavy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,13 @@ describe('ThreadJobService heavy tasks', () => {
await Promise.all(multiThreadJobs);
console.log('ends with multi thread');
performance.mark('end');

const singleThreadJobDuration: number = getAverageJobDuration(await Promise.all(jobs));
const multiThreadJobDuration: number = getAverageJobDuration(await Promise.all(multiThreadJobs));
expect(multiThreadJobDuration * 0.85).to.be.below(singleThreadJobDuration);

const totalWithMultiThread: number = performance.measure('totalMultiThread', 'start', 'end').duration;
expect(totalWithMultiThread * (numberOfJobs - 2)).to.be.below(totalWithSingleThread);
expect(totalWithMultiThread * (numberOfJobs - 1)).to.be.below(totalWithSingleThread);
}).timeout(200000);

afterEach(async () => {
Expand All @@ -137,4 +142,9 @@ describe('ThreadJobService heavy tasks', () => {
await threadJobService.shutdown();
await repository.deleteAll();
});
});
});

function getAverageJobDuration(jobs: ThreadJobEntity<BaseWorkerData, unknown>[]): number {
const total: number = jobs.reduce((prev, next) => prev + (next.stoppedAtMs as number) - (next.startedAtMs as number), 0);
return total / jobs.length;
}
30 changes: 14 additions & 16 deletions src/services/worker/thread-job.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,24 @@ parentPort.on('message', (wData: BaseWorkerData | FunctionWorkerData<unknown>) =
// @ts-ignore-next-line
workerData = wData;

// Clear the module from the cache
if (wData.filePath.length) {
if (wData.filePath.endsWith('.ts')) {
const parts: string[] = wData.filePath.split('.ts');
parts.splice(parts.length - 1, 1);
wData.filePath = parts.join('') + '.js';
}

if (require.cache[require.resolve(wData.filePath)]) {
// eslint-disable-next-line typescript/no-dynamic-delete
delete require.cache[require.resolve(wData.filePath)];
}
}

if (isFunctionWorkerData(wData)) {
void callFunction(wData);
return;
}
else {
void importWorkerFile(wData);

// Clear the module from the cache
if (wData.filePath.endsWith('.ts')) {
const parts: string[] = wData.filePath.split('.ts');
parts.splice(parts.length - 1, 1);
wData.filePath = parts.join('') + '.js';
}

if (require.cache[require.resolve(wData.filePath)]) {
// eslint-disable-next-line typescript/no-dynamic-delete
delete require.cache[require.resolve(wData.filePath)];
}

void importWorkerFile(wData);
});

async function callFunction(wData: FunctionWorkerData<unknown>): Promise<void> {
Expand Down

0 comments on commit c5def66

Please sign in to comment.