Skip to content

Commit a14d1bf

Browse files
authored
[FSSDK-12025] expose maxRetries option for createBatchEventProcessor (#1106)
1 parent f7b2554 commit a14d1bf

7 files changed

+44
-10
lines changed

lib/event_processor/event_processor_factory.browser.spec.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,22 @@ describe('createBatchEventProcessor', () => {
193193
expect(mockGetOpaqueBatchEventProcessor.mock.calls[1][0].batchSize).toBe(undefined);
194194
});
195195

196-
it('uses maxRetries value of 5', () => {
196+
it('uses maxRetries value of 5 by default', () => {
197197
const processor = createBatchEventProcessor({ });
198198
expect(Object.is(processor, mockGetOpaqueBatchEventProcessor.mock.results[0].value)).toBe(true);
199199
expect(mockGetOpaqueBatchEventProcessor.mock.calls[0][0].retryOptions?.maxRetries).toBe(5);
200200
});
201201

202+
it('uses the provided maxRetries value', () => {
203+
const processor1 = createBatchEventProcessor({ maxRetries: 3 });
204+
expect(Object.is(processor1, mockGetOpaqueBatchEventProcessor.mock.results[0].value)).toBe(true);
205+
expect(mockGetOpaqueBatchEventProcessor.mock.calls[0][0].retryOptions?.maxRetries).toBe(3);
206+
207+
const processor2 = createBatchEventProcessor({ maxRetries: 10 });
208+
expect(Object.is(processor2, mockGetOpaqueBatchEventProcessor.mock.results[1].value)).toBe(true);
209+
expect(mockGetOpaqueBatchEventProcessor.mock.calls[1][0].retryOptions?.maxRetries).toBe(10);
210+
});
211+
202212
it('uses the default failedEventRetryInterval', () => {
203213
const processor = createBatchEventProcessor({ });
204214
expect(Object.is(processor, mockGetOpaqueBatchEventProcessor.mock.results[0].value)).toBe(true);

lib/event_processor/event_processor_factory.browser.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { DEFAULT_MAX_EVENTS_IN_STORE, EventStore } from './event_store';
3232

3333
export const DEFAULT_EVENT_BATCH_SIZE = 10;
3434
export const DEFAULT_EVENT_FLUSH_INTERVAL = 1_000;
35+
export const EVENT_MAX_RETRIES_BROWSER = 5;
3536

3637
export const createForwardingEventProcessor = (
3738
eventDispatcher: EventDispatcher = defaultEventDispatcher,
@@ -51,14 +52,14 @@ export const createBatchEventProcessor = (
5152

5253
return getOpaqueBatchEventProcessor({
5354
eventDispatcher: options.eventDispatcher || defaultEventDispatcher,
54-
closingEventDispatcher: options.closingEventDispatcher ||
55+
closingEventDispatcher: options.closingEventDispatcher ||
5556
(options.eventDispatcher ? undefined : sendBeaconEventDispatcher),
5657
flushInterval: options.flushInterval,
5758
batchSize: options.batchSize,
5859
defaultFlushInterval: DEFAULT_EVENT_FLUSH_INTERVAL,
5960
defaultBatchSize: DEFAULT_EVENT_BATCH_SIZE,
6061
retryOptions: {
61-
maxRetries: 5,
62+
maxRetries: options.maxRetries ?? EVENT_MAX_RETRIES_BROWSER,
6263
},
6364
failedEventRetryInterval: FAILED_EVENT_RETRY_INTERVAL,
6465
eventStore,

lib/event_processor/event_processor_factory.node.spec.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,22 @@ describe('createBatchEventProcessor', () => {
184184
expect(mockGetOpaqueBatchEventProcessor.mock.calls[1][0].batchSize).toBe(undefined);
185185
});
186186

187-
it('uses maxRetries value of 5', () => {
187+
it('uses maxRetries value of 5 by default', () => {
188188
const processor = createBatchEventProcessor({ });
189189
expect(Object.is(processor, mockGetOpaqueBatchEventProcessor.mock.results[0].value)).toBe(true);
190190
expect(mockGetOpaqueBatchEventProcessor.mock.calls[0][0].retryOptions?.maxRetries).toBe(5);
191191
});
192192

193+
it('uses the provided maxRetries value', () => {
194+
const processor1 = createBatchEventProcessor({ maxRetries: 3 });
195+
expect(Object.is(processor1, mockGetOpaqueBatchEventProcessor.mock.results[0].value)).toBe(true);
196+
expect(mockGetOpaqueBatchEventProcessor.mock.calls[0][0].retryOptions?.maxRetries).toBe(3);
197+
198+
const processor2 = createBatchEventProcessor({ maxRetries: 10 });
199+
expect(Object.is(processor2, mockGetOpaqueBatchEventProcessor.mock.results[1].value)).toBe(true);
200+
expect(mockGetOpaqueBatchEventProcessor.mock.calls[1][0].retryOptions?.maxRetries).toBe(10);
201+
});
202+
193203
it('uses no failed event retry if an eventStore is not provided', () => {
194204
const processor = createBatchEventProcessor({ });
195205
expect(Object.is(processor, mockGetOpaqueBatchEventProcessor.mock.results[0].value)).toBe(true);

lib/event_processor/event_processor_factory.node.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727

2828
export const DEFAULT_EVENT_BATCH_SIZE = 10;
2929
export const DEFAULT_EVENT_FLUSH_INTERVAL = 30_000;
30+
export const EVENT_MAX_RETRIES_NODE = 5;
3031

3132
export const createForwardingEventProcessor = (
3233
eventDispatcher: EventDispatcher = defaultEventDispatcher,
@@ -38,7 +39,7 @@ export const createBatchEventProcessor = (
3839
options: BatchEventProcessorOptions = {}
3940
): OpaqueEventProcessor => {
4041
const eventStore = options.eventStore ? getPrefixEventStore(options.eventStore) : undefined;
41-
42+
4243
return getOpaqueBatchEventProcessor({
4344
eventDispatcher: options.eventDispatcher || defaultEventDispatcher,
4445
closingEventDispatcher: options.closingEventDispatcher,
@@ -47,8 +48,8 @@ export const createBatchEventProcessor = (
4748
defaultFlushInterval: DEFAULT_EVENT_FLUSH_INTERVAL,
4849
defaultBatchSize: DEFAULT_EVENT_BATCH_SIZE,
4950
retryOptions: {
50-
maxRetries: 5,
51-
51+
maxRetries: options.maxRetries ?? EVENT_MAX_RETRIES_NODE,
52+
5253
},
5354
failedEventRetryInterval: eventStore ? FAILED_EVENT_RETRY_INTERVAL : undefined,
5455
eventStore,

lib/event_processor/event_processor_factory.react_native.spec.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,22 @@ describe('createBatchEventProcessor', () => {
278278
expect(mockGetOpaqueBatchEventProcessor.mock.calls[1][0].batchSize).toBe(undefined);
279279
});
280280

281-
it('uses maxRetries value of 5', () => {
281+
it('uses maxRetries value of 5 by default', () => {
282282
const processor = createBatchEventProcessor({});
283283
expect(Object.is(processor, mockGetOpaqueBatchEventProcessor.mock.results[0].value)).toBe(true);
284284
expect(mockGetOpaqueBatchEventProcessor.mock.calls[0][0].retryOptions?.maxRetries).toBe(5);
285285
});
286286

287+
it('uses the provided maxRetries value', () => {
288+
const processor1 = createBatchEventProcessor({ maxRetries: 3 });
289+
expect(Object.is(processor1, mockGetOpaqueBatchEventProcessor.mock.results[0].value)).toBe(true);
290+
expect(mockGetOpaqueBatchEventProcessor.mock.calls[0][0].retryOptions?.maxRetries).toBe(3);
291+
292+
const processor2 = createBatchEventProcessor({ maxRetries: 10 });
293+
expect(Object.is(processor2, mockGetOpaqueBatchEventProcessor.mock.results[1].value)).toBe(true);
294+
expect(mockGetOpaqueBatchEventProcessor.mock.calls[1][0].retryOptions?.maxRetries).toBe(10);
295+
});
296+
287297
it('uses the default failedEventRetryInterval', () => {
288298
const processor = createBatchEventProcessor({});
289299
expect(Object.is(processor, mockGetOpaqueBatchEventProcessor.mock.results[0].value)).toBe(true);

lib/event_processor/event_processor_factory.react_native.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { DEFAULT_MAX_EVENTS_IN_STORE, EventStore } from './event_store';
3131

3232
export const DEFAULT_EVENT_BATCH_SIZE = 10;
3333
export const DEFAULT_EVENT_FLUSH_INTERVAL = 1_000;
34+
export const EVENT_MAX_RETRIES_REACT_NATIVE = 5;
3435

3536
export const createForwardingEventProcessor = (
3637
eventDispatcher: EventDispatcher = defaultEventDispatcher,
@@ -47,7 +48,7 @@ export const createBatchEventProcessor = (
4748
: DEFAULT_MAX_EVENTS_IN_STORE,
4849
ttl: options.storeTtl,
4950
});
50-
51+
5152
return getOpaqueBatchEventProcessor(
5253
{
5354
eventDispatcher: options.eventDispatcher || defaultEventDispatcher,
@@ -57,7 +58,7 @@ export const createBatchEventProcessor = (
5758
defaultFlushInterval: DEFAULT_EVENT_FLUSH_INTERVAL,
5859
defaultBatchSize: DEFAULT_EVENT_BATCH_SIZE,
5960
retryOptions: {
60-
maxRetries: 5,
61+
maxRetries: options.maxRetries ?? EVENT_MAX_RETRIES_REACT_NATIVE,
6162
},
6263
failedEventRetryInterval: FAILED_EVENT_RETRY_INTERVAL,
6364
eventStore,

lib/event_processor/event_processor_factory.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export type BatchEventProcessorOptions = {
6161
batchSize?: number;
6262
storeTtl?: number;
6363
eventStore?: Store<string>;
64+
maxRetries?: number;
6465
};
6566

6667
export type BatchEventProcessorFactoryOptions = Omit<BatchEventProcessorOptions, 'eventDispatcher' | 'eventStore' > & {

0 commit comments

Comments
 (0)