1
- import { AbstractPeriodicJob , type JobExecutionContext } from '@lokalise/background-jobs-common'
2
1
import type { PeriodicJobDependencies } from '@lokalise/background-jobs-common'
2
+ import { AbstractPeriodicJob , type JobExecutionContext } from '@lokalise/background-jobs-common'
3
3
import type {
4
4
CommonEventDefinition ,
5
5
CommonEventDefinitionPublisherSchemaType ,
@@ -9,6 +9,7 @@ import type {
9
9
import { PromisePool } from '@supercharge/promise-pool'
10
10
import { uuidv7 } from 'uuidv7'
11
11
import type { OutboxAccumulator } from './accumulators'
12
+ import type { OutboxEntry } from './objects'
12
13
import type { OutboxStorage } from './storage'
13
14
14
15
export type OutboxDependencies < SupportedEvents extends CommonEventDefinition [ ] > = {
@@ -42,10 +43,8 @@ export class OutboxProcessor<SupportedEvents extends CommonEventDefinition[]> {
42
43
43
44
const entries = await outboxStorage . getEntries ( this . outboxProcessorConfiguration . maxRetryCount )
44
45
45
- const currentEntriesInAccumulator = new Set (
46
- ( await outboxAccumulator . getEntries ( ) ) . map ( ( entry ) => entry . id ) ,
47
- )
48
- const filteredEntries = entries . filter ( ( entry ) => ! currentEntriesInAccumulator . has ( entry . id ) )
46
+ const filteredEntries =
47
+ entries . length === 0 ? entries : await this . getFilteredEntries ( entries , outboxAccumulator )
49
48
50
49
await PromisePool . for ( filteredEntries )
51
50
. withConcurrency ( this . outboxProcessorConfiguration . emitBatchSize )
@@ -63,6 +62,16 @@ export class OutboxProcessor<SupportedEvents extends CommonEventDefinition[]> {
63
62
await outboxStorage . flush ( outboxAccumulator )
64
63
await outboxAccumulator . clear ( )
65
64
}
65
+
66
+ private async getFilteredEntries (
67
+ entries : OutboxEntry < SupportedEvents [ number ] > [ ] ,
68
+ outboxAccumulator : OutboxAccumulator < SupportedEvents > ,
69
+ ) {
70
+ const currentEntriesInAccumulator = new Set (
71
+ ( await outboxAccumulator . getEntries ( ) ) . map ( ( entry ) => entry . id ) ,
72
+ )
73
+ return entries . filter ( ( entry ) => ! currentEntriesInAccumulator . has ( entry . id ) )
74
+ }
66
75
}
67
76
68
77
/**
0 commit comments