Skip to content

Commit 362ce47

Browse files
committed
feat: add more code for initial thread method
1 parent b2f445c commit 362ce47

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

apps/api/src/instrument-records/instrument-records.service.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Worker } from 'worker_threads';
55

66
const __dirname = dirname(fileURLToPath(import.meta.url));
77

8-
import { replacer, reviver } from '@douglasneuroinformatics/libjs';
8+
import { replacer, reviver, yearsPassed } from '@douglasneuroinformatics/libjs';
99
import { InjectModel } from '@douglasneuroinformatics/libnest';
1010
import type { Model } from '@douglasneuroinformatics/libnest';
1111
import { linearRegression } from '@douglasneuroinformatics/libstats';
@@ -37,6 +37,8 @@ import { SubjectsService } from '@/subjects/subjects.service';
3737
import { InstrumentMeasuresService } from './instrument-measures.service';
3838

3939
import type { ChunkCompleteData, ChunkCompleteMessage, InitData, InitMessage, ParentMessage } from './thread-types';
40+
import { DEFAULT_GROUP_NAME } from '@opendatacapture/schemas/core';
41+
import { removeSubjectIdScope } from '@opendatacapture/subject-utils';
4042

4143
type ExpandDataType =
4244
| {
@@ -51,6 +53,8 @@ type ExpandDataType =
5153

5254
type WorkerMessage = { data: InstrumentRecordsExport; success: true } | { error: string; success: false };
5355

56+
type InitialMessage = { success: true };
57+
5458
// type MainThreadMessage = {
5559
// data: {
5660

@@ -261,8 +265,15 @@ export class InstrumentRecordsService {
261265
});
262266

263267
const initWorker = new Worker(join(__dirname, 'export-worker.ts'));
268+
264269
initWorker.postMessage({ data: availableInstrumentArray, type: 'INIT' });
265270

271+
initWorker.on('message', (message: InitialMessage) => {
272+
if (!message.success) {
273+
throw Error('Initial thread failed');
274+
}
275+
});
276+
266277
const workerPromises = chunks.map((chunk) => {
267278
return new Promise<InstrumentRecordsExport>((resolve, reject) => {
268279
const worker = new Worker(join(__dirname, 'export-worker.ts'));

0 commit comments

Comments
 (0)