@@ -111,9 +111,17 @@ open class DefaultEventDispatcher : BackgroundingCallbacks, OPTEventDispatcher {
111111
112112 }
113113 while let eventsToSend: [ EventForDispatch ] = self . dataStore. getFirstItems ( count: self . batchSize) {
114+ let actualEventsSize = eventsToSend. count
114115 var eventToSend = eventsToSend. batch ( )
115116 if let _ = eventToSend {
116117 // we merged the event and ready for batch
118+ // if the bacth size is not equal to the actual event size,
119+ // then setup the batchSizeHolder to be the size of the event.
120+ if actualEventsSize != self . batchSize {
121+ batchSizeHolder = actualEventsSize
122+ self . batchSize = actualEventsSize
123+ sendCount = actualEventsSize - 1
124+ }
117125 }
118126 else {
119127 failedBatch ( )
@@ -145,7 +153,7 @@ open class DefaultEventDispatcher : BackgroundingCallbacks, OPTEventDispatcher {
145153 failureCount += 1
146154 case . success( _) :
147155 // we succeeded. remove the batch size sent.
148- if let removedItem: [ EventForDispatch ] = self . dataStore. removeFirstItems ( count: self . batchSize ) {
156+ if let removedItem: [ EventForDispatch ] = self . dataStore. removeFirstItems ( count: failureCount > 0 ? 1 : actualEventsSize ) {
149157 if self . batchSize == 1 && removedItem. first != event {
150158 self . logger? . e ( " Removed event different from sent event " )
151159 }
@@ -181,7 +189,7 @@ open class DefaultEventDispatcher : BackgroundingCallbacks, OPTEventDispatcher {
181189
182190 }
183191
184- func sendEvent( event: EventForDispatch , completionHandler: @escaping DispatchCompletionHandler ) {
192+ open func sendEvent( event: EventForDispatch , completionHandler: @escaping DispatchCompletionHandler ) {
185193 let config = URLSessionConfiguration . ephemeral
186194 let session = URLSession ( configuration: config)
187195 var request = URLRequest ( url: event. url)
0 commit comments