Skip to content

Commit

Permalink
feat(geoprocessing): scenarios-pu-inclusion: worker shell
Browse files Browse the repository at this point in the history
  • Loading branch information
kgajowy committed Jun 9, 2021
1 parent d7e0c2b commit 21e3815
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Test } from '@nestjs/testing';
import { JobInput } from '@marxan-jobs/planning-unit-geometry';
import { Queue } from 'bullmq';
import { QueueService } from '../../../../queue/queue.service';
import { AsyncJobsAdapter } from './async-jobs-adapter';
import { RequestJobInput } from '../request-job.port';

let sut: AsyncJobsAdapter;
let addJobMock: jest.SpyInstance;
Expand All @@ -17,7 +17,7 @@ beforeEach(async () => {
queue: ({
add: addJobMock,
} as unknown) as Queue,
} as unknown) as QueueService<RequestJobInput>,
} as unknown) as QueueService<JobInput>,
},
AsyncJobsAdapter,
],
Expand Down
2 changes: 2 additions & 0 deletions api/apps/geoprocessing/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { TileModule } from './modules/tile/tile.module';
import { FeaturesModule } from '@marxan-geoprocessing/modules/features/features.module';
import { ApiEventsModule } from './modules/api-events/api-events.module';
import { SurfaceCostModule } from './modules/surface-cost/surface-cost.module';
import { ScenarioPlanningUnitsInclusionModule } from '@marxan-geoprocessing/modules/scenario-planning-units-inclusion/scenario-planning-units-inclusion.module';

@Module({
imports: [
Expand All @@ -28,6 +29,7 @@ import { SurfaceCostModule } from './modules/surface-cost/surface-cost.module';
FeaturesModule,
ApiEventsModule,
SurfaceCostModule,
ScenarioPlanningUnitsInclusionModule,
],
controllers: [AppController],
providers: [AppService],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Injectable } from '@nestjs/common';
import { Job } from 'bullmq';
import { WorkerProcessor } from '@marxan-geoprocessing/modules/worker';
import { JobInput } from '@marxan-jobs/planning-unit-geometry';

@Injectable()
export class ScenarioPlanningUnitsInclusionProcessor
implements WorkerProcessor<JobInput, true> {
async process(_job: Job<JobInput, true>): Promise<true> {
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Module } from '@nestjs/common';
import { CqrsModule } from '@nestjs/cqrs';

import { WorkerModule } from '@marxan-geoprocessing/modules/worker';

import { ScenarioPlanningUnitsInclusionProcessor } from './scenario-planning-units-inclusion-processor';
import { ScenarioPlanningUnitsInclusionWorker } from './scenario-planning-units-inclusion.worker';

@Module({
imports: [WorkerModule, CqrsModule],
providers: [
ScenarioPlanningUnitsInclusionWorker,
ScenarioPlanningUnitsInclusionProcessor,
],
})
export class ScenarioPlanningUnitsInclusionModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Injectable } from '@nestjs/common';
import { Job, Worker } from 'bullmq';

import { WorkerBuilder } from '@marxan-geoprocessing/modules/worker';

import { queueName, JobInput } from '@marxan-jobs/planning-unit-geometry';
import { ScenarioPlanningUnitsInclusionProcessor } from './scenario-planning-units-inclusion-processor';

@Injectable()
export class ScenarioPlanningUnitsInclusionWorker {
#worker: Worker;

constructor(
private readonly wrapper: WorkerBuilder,
// private readonly eventBus: EventBus,
private readonly processor: ScenarioPlanningUnitsInclusionProcessor,
) {
this.#worker = wrapper.build(queueName, processor);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
this.#worker.on('completed', ({ data }: Job<JobInput>) => {
// this.eventBus.publish(
// new ApiEvent(
// data.scenarioId,
// API_EVENT_KINDS....,
// ),
// );
});
this.#worker.on(
'failed',
// eslint-disable-next-line @typescript-eslint/no-unused-vars
({ data, failedReason, attemptsMade, opts }: Job<JobInput>) => {
if (attemptsMade !== opts.attempts) {
return;
}
// this.eventBus.publish(
// new ApiEvent(
// data.scenarioId,
// API_EVENT_KINDS.....,
// {
// error: failedReason,
// },
// ),
// );
},
);
}
}

0 comments on commit 21e3815

Please sign in to comment.