Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions packages/core/lib/plugins/segment_destination.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,25 @@ class SegmentDestination extends DestinationPlugin with Flushable {
final List<RawEvent> sentEvents = [];
var numFailedEvents = 0;

// Iterate over each batch in chunkedEvents sequentially
await Future.forEach(chunkedEvents, (batch) async {
try {
final succeeded = await analytics?.httpClient.startBatchUpload(
analytics!.state.configuration.state.writeKey, batch,
host: _apiHost);
if (succeeded == null || !succeeded) {
if (succeeded == true) { // If the upload succeeded, all events in the batch are added to sentEvents.
sentEvents.addAll(batch);
} else { // If it failed, increase the numFailedEvents counter by the number of events in the failed batch.
numFailedEvents += batch.length;
}
sentEvents.addAll(batch);
} catch (e) {
numFailedEvents += batch.length;
} finally {
_queuePlugin.dequeue(sentEvents);
}
});

if (sentEvents.isNotEmpty) {
log("Sent ${sentEvents.length} events", kind: LogFilterKind.debug);
_queuePlugin.dequeue(sentEvents); // Removed events that were successfully sent from the internal queue
log("Successfully Sent ${sentEvents.length} events", kind: LogFilterKind.debug);
}

if (numFailedEvents > 0) {
Expand Down