Skip to content

Commit

Permalink
Fix: add conditional to queue restoration error reporting (#999)
Browse files Browse the repository at this point in the history
* fix: add check to limit console warnings for queue restore

* chore: remove dev team

* feat: add message for success if warning was sent

* fix: fix Segmentclient import

* fix: reset timeoutWarned to true on resolved promise
  • Loading branch information
alanjcharles authored Sep 12, 2024
1 parent c1a0957 commit 28ecfb6
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,11 @@
"-DFOLLY_MOBILE=1",
"-DFOLLY_USE_LIBCPP=1",
);
OTHER_LDFLAGS = "$(inherited)";
OTHER_LDFLAGS = (
"$(inherited)",
"-Wl",
"-ld_classic",
);
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
};
Expand Down Expand Up @@ -672,7 +676,11 @@
"-DFOLLY_MOBILE=1",
"-DFOLLY_USE_LIBCPP=1",
);
OTHER_LDFLAGS = "$(inherited)";
OTHER_LDFLAGS = (
"$(inherited)",
"-Wl",
"-ld_classic",
);
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
VALIDATE_PRODUCT = YES;
Expand Down
4 changes: 2 additions & 2 deletions examples/AnalyticsReactNativeExample/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ PODS:
- RNScreens (3.27.0):
- RCT-Folly (= 2021.07.22.00)
- React-Core
- segment-analytics-react-native (2.19.3):
- segment-analytics-react-native (2.19.4):
- React-Core
- sovran-react-native
- SocketRocket (0.6.1)
Expand Down Expand Up @@ -752,7 +752,7 @@ SPEC CHECKSUMS:
RNCMaskedView: 0e1bc4bfa8365eba5fbbb71e07fbdc0555249489
RNGestureHandler: 32a01c29ecc9bb0b5bf7bc0a33547f61b4dc2741
RNScreens: 3c2d122f5e08c192e254c510b212306da97d2581
segment-analytics-react-native: a803de6a9406f7b18928d352962c2f49663a0869
segment-analytics-react-native: 49ce29a68e86b38c084f1ce07b0c128273d169f9
SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17
sovran-react-native: 5f02bd2d111ffe226d00c7b0435290eae6f10934
Yoga: eddf2bbe4a896454c248a8f23b4355891eb720a6
Expand Down
10 changes: 5 additions & 5 deletions examples/E2E/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -499,11 +499,11 @@ PODS:
- RNScreens (3.27.0):
- RCT-Folly (= 2021.07.22.00)
- React-Core
- segment-analytics-react-native (2.19.2):
- segment-analytics-react-native (2.19.4):
- React-Core
- sovran-react-native
- SocketRocket (0.6.1)
- sovran-react-native (1.1.1):
- sovran-react-native (1.1.2):
- React-Core
- Yoga (1.14.0)
- YogaKit (1.18.1):
Expand Down Expand Up @@ -752,12 +752,12 @@ SPEC CHECKSUMS:
RNCMaskedView: 0e1bc4bfa8365eba5fbbb71e07fbdc0555249489
RNGestureHandler: 32a01c29ecc9bb0b5bf7bc0a33547f61b4dc2741
RNScreens: 3c2d122f5e08c192e254c510b212306da97d2581
segment-analytics-react-native: 962494a9edbe3f6c5829e3b471484c85c304601c
segment-analytics-react-native: 49ce29a68e86b38c084f1ce07b0c128273d169f9
SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17
sovran-react-native: e6a9c963a8a6b9ebc3563394c39c30f33ab1453f
sovran-react-native: 5f02bd2d111ffe226d00c7b0435290eae6f10934
Yoga: eddf2bbe4a896454c248a8f23b4355891eb720a6
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a

PODFILE CHECKSUM: 9d352ca8db1e31a063d2585ed47fdadabf87fe90

COCOAPODS: 1.15.2
COCOAPODS: 1.11.3
27 changes: 24 additions & 3 deletions packages/core/src/plugins/QueueFlushingPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { defaultConfig } from '../constants';
import { UtilityPlugin } from '../plugin';
import { PluginType, SegmentEvent } from '../types';
import { createPromise } from '../util';

import { ErrorType, SegmentError } from '../errors';
/**
* This plugin manages a queue where all events get added to after timeline processing.
* It takes a onFlush callback to trigger any action particular to your destination sending events.
Expand All @@ -20,6 +20,7 @@ export class QueueFlushingPlugin extends UtilityPlugin {
private onFlush: (events: SegmentEvent[]) => Promise<void>;
private isRestoredResolve: () => void;
private isRestored: Promise<void>;
private timeoutWarned = false;

/**
* @param onFlush callback to execute when the queue is flushed (either by reaching the limit or manually) e.g. code to upload events to your destination
Expand Down Expand Up @@ -75,12 +76,32 @@ export class QueueFlushingPlugin extends UtilityPlugin {
// Wait for the queue to be restored
try {
await this.isRestored;

if (this.timeoutWarned === true) {
this.analytics?.logger.info('Flush triggered successfully.');

this.timeoutWarned = false;
}
} catch (e) {
// If the queue is not restored before the timeout, we will notify but not block flushing events
console.info(
'Flush triggered but queue restoration and settings loading not complete. Flush will be retried.'
this.analytics?.reportInternalError(
new SegmentError(
ErrorType.InitializationError,
'Queue restoration timeout',
e
)
);

if (this.timeoutWarned === false) {
this.analytics?.logger.warn(
'Flush triggered but queue restoration and settings loading not complete. Flush will be retried.',
e
);

this.timeoutWarned = true;
}
}

const events = (await this.queueStore?.getState(true))?.events ?? [];
if (!this.isPendingUpload) {
try {
Expand Down

0 comments on commit 28ecfb6

Please sign in to comment.