Skip to content

Commit

Permalink
refactor(core): introduce ITerminate and rename outbox dispose
Browse files Browse the repository at this point in the history
  • Loading branch information
gtoselli committed Apr 3, 2024
1 parent 9ef1419 commit c48497c
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/ddd-toolkit/src/outbox/mongo-outbox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('Mongo outbox', () => {
});

afterAll(async () => {
await outbox.dispose();
await outbox.terminate();
await mongoClient.close();
await mongodb.stop();
});
Expand Down
5 changes: 3 additions & 2 deletions packages/ddd-toolkit/src/outbox/mongo-outbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { inspect } from 'util';
import { difference, intersection } from 'lodash';
import { IOutbox } from './outbox.interface';
import { IInit } from '../init.interface';
import { ITerminate } from '../terminate.interface';

type OutboxEventModel = {
event: IEvent<unknown>;
Expand All @@ -14,7 +15,7 @@ type OutboxEventModel = {
contextName?: string;
};

export class MongoOutbox implements IOutbox, IInit {
export class MongoOutbox implements IOutbox, IInit, ITerminate {
private outboxCollection: Collection<OutboxEventModel>;

private stopping = false;
Expand All @@ -35,7 +36,7 @@ export class MongoOutbox implements IOutbox, IInit {
void this.checkScheduledEvents([]);
}

public async dispose() {
public async terminate() {
this.stopping = true;
await sleep(this.monitoringIntervalMs);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ddd-toolkit/src/outbox/outbox.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { IEvent } from '../event-bus/event-bus.interface';
export interface IOutbox {
init(): Promise<void>;

dispose(): Promise<void>;
terminate(): Promise<void>;

scheduleEvents(events: IEvent<unknown>[], transaction: unknown): Promise<string[]>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('MongoAggregateRepo MongoDB Integration', () => {
});

afterAll(async () => {
await outbox.dispose();
await outbox.terminate();
await mongoClient.close();
await mongodb.stop();
});
Expand Down
3 changes: 3 additions & 0 deletions packages/ddd-toolkit/src/terminate.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface ITerminate {
terminate(): Promise<void> | void;
}

0 comments on commit c48497c

Please sign in to comment.