in Sources/Confidence/EventSenderEngine.swift [92:123]
func upload() async {
await withSemaphore { [weak self] in
guard let self = self else { return }
do {
try self.storage.startNewBatch()
let ids = try storage.batchReadyIds()
if ids.isEmpty {
return
}
for id in ids {
let events: [NetworkEvent] = try self.storage.eventsFrom(id: id)
.compactMap { event in
return NetworkEvent(
eventDefinition: event.name,
payload: NetworkStruct(fields: TypeMapper.convert(structure: event.payload).fields),
eventTime: Date.backport.toISOString(date: event.eventTime))
}
var shouldCleanup = false
if events.isEmpty {
shouldCleanup = true
} else {
shouldCleanup = try await self.uploader.upload(events: events)
}
if shouldCleanup {
try storage.remove(id: id)
}
}
} catch {
}
}
}