Skip to content

Commit 94bbe85

Browse files
committed
AP-5046 OutboxProcessorConfig.
1 parent 29bc350 commit 94bbe85

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

packages/outbox-core/lib/outbox.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,7 @@ describe('outbox', () => {
151151
outboxAccumulator: new InMemoryOutboxAccumulator(),
152152
eventEmitter,
153153
} satisfies OutboxDependencies<TestEventsType>,
154-
MAX_RETRY_COUNT,
155-
1,
154+
{ maxRetryCount: MAX_RETRY_COUNT, emitBatchSize: 1 },
156155
)
157156
})
158157

packages/outbox-core/lib/outbox.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@ export type OutboxDependencies<SupportedEvents extends CommonEventDefinition[]>
1717
eventEmitter: DomainEventEmitter<SupportedEvents>
1818
}
1919

20-
export type OutboxConfiguration = {
20+
export type OutboxProcessorConfiguration = {
2121
maxRetryCount: number
2222
emitBatchSize: number
23-
jobIntervalInMs: number
2423
}
2524

25+
export type OutboxConfiguration = {
26+
jobIntervalInMs: number
27+
} & OutboxProcessorConfiguration
28+
2629
/**
2730
* Main logic for handling outbox entries.
2831
*
@@ -31,17 +34,16 @@ export type OutboxConfiguration = {
3134
export class OutboxProcessor<SupportedEvents extends CommonEventDefinition[]> {
3235
constructor(
3336
private readonly outboxDependencies: OutboxDependencies<SupportedEvents>,
34-
private readonly maxRetryCount: number,
35-
private readonly emitBatchSize: number,
37+
private readonly outboxProcessorConfiguration: OutboxProcessorConfiguration,
3638
) {}
3739

3840
public async processOutboxEntries(context: JobExecutionContext) {
3941
const { outboxStorage, eventEmitter, outboxAccumulator } = this.outboxDependencies
4042

41-
const entries = await outboxStorage.getEntries(this.maxRetryCount)
43+
const entries = await outboxStorage.getEntries(this.outboxProcessorConfiguration.maxRetryCount)
4244

4345
await PromisePool.for(entries)
44-
.withConcurrency(this.emitBatchSize)
46+
.withConcurrency(this.outboxProcessorConfiguration.emitBatchSize)
4547
.process(async (entry) => {
4648
try {
4749
await eventEmitter.emit(entry.event, entry.data, entry.precedingMessageMetadata)
@@ -96,8 +98,7 @@ export class OutboxPeriodicJob<
9698

9799
this.outboxProcessor = new OutboxProcessor<SupportedEvents>(
98100
outboxDependencies,
99-
outboxConfiguration.maxRetryCount,
100-
outboxConfiguration.emitBatchSize,
101+
outboxConfiguration,
101102
)
102103
}
103104

0 commit comments

Comments
 (0)