@@ -28,13 +28,13 @@ open class DefaultEventDispatcher : BackgroundingCallbacks, OPTEventDispatcher {
28
28
static let MAX_FAILURE_COUNT = 3
29
29
30
30
// default timerInterval
31
- open var timerInterval : TimeInterval = 60 * 5 // every five minutes
31
+ var timerInterval : TimeInterval = 60 * 5 // every five minutes
32
32
// default batchSize.
33
33
// attempt to send events in batches with batchSize number of events combined
34
- open var batchSize : Int = 10
34
+ var batchSize : Int = 10
35
35
// start trimming the front of the queue when we get to over maxQueueSize
36
36
// TODO: implement
37
- open var maxQueueSize : Int = 3000
37
+ var maxQueueSize : Int = 30000
38
38
39
39
lazy var logger = HandlerRegistryService . shared. injectLogger ( )
40
40
var backingStore : DataStoreType = . file
@@ -47,9 +47,8 @@ open class DefaultEventDispatcher : BackgroundingCallbacks, OPTEventDispatcher {
47
47
// timer as a atomic property.
48
48
var timer : AtomicProperty < Timer > = AtomicProperty < Timer > ( )
49
49
50
- public init ( batchSize: Int = 10 , maxQueueSize: Int = 3000 , backingStore: DataStoreType = . file, dataStoreName: String = " OPTEventQueue " , timerInterval: TimeInterval = 60 * 5 ) {
51
- self . batchSize = batchSize
52
- self . maxQueueSize = maxQueueSize
50
+ public init ( batchSize: Int = 10 , backingStore: DataStoreType = . file, dataStoreName: String = " OPTEventQueue " , timerInterval: TimeInterval = 60 * 5 ) {
51
+ self . batchSize = batchSize > 0 ? batchSize : 1
53
52
self . backingStore = backingStore
54
53
self . backingStoreName = dataStoreName
55
54
self . timerInterval = timerInterval
@@ -112,9 +111,17 @@ open class DefaultEventDispatcher : BackgroundingCallbacks, OPTEventDispatcher {
112
111
113
112
}
114
113
while let eventsToSend: [ EventForDispatch ] = self . dataStore. getFirstItems ( count: self . batchSize) {
114
+ let actualEventsSize = eventsToSend. count
115
115
var eventToSend = eventsToSend. batch ( )
116
116
if let _ = eventToSend {
117
117
// 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
+ }
118
125
}
119
126
else {
120
127
failedBatch ( )
@@ -182,7 +189,7 @@ open class DefaultEventDispatcher : BackgroundingCallbacks, OPTEventDispatcher {
182
189
183
190
}
184
191
185
- func sendEvent( event: EventForDispatch , completionHandler: @escaping DispatchCompletionHandler ) {
192
+ open func sendEvent( event: EventForDispatch , completionHandler: @escaping DispatchCompletionHandler ) {
186
193
let config = URLSessionConfiguration . ephemeral
187
194
let session = URLSession ( configuration: config)
188
195
var request = URLRequest ( url: event. url)
0 commit comments