Skip to content

Commit

Permalink
Merge pull request #899 from snowplow/release/6.0.5
Browse files Browse the repository at this point in the history
Release/6.0.5
  • Loading branch information
matus-tomlein authored Jul 3, 2024
2 parents 50e7912 + 28df8a6 commit 18f62a1
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 22 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: latest-stable
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Lint Podspec
run: pod lib lint --platforms=${{ matrix.platform }}

Expand Down Expand Up @@ -56,12 +56,12 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

# -- Micro --
- name: Cache Micro
id: cache-micro
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: micro.jar
key: ${{ runner.os }}-micro
Expand Down Expand Up @@ -130,7 +130,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: true

Expand Down Expand Up @@ -167,7 +167,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: true

Expand Down Expand Up @@ -204,7 +204,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: true

Expand Down Expand Up @@ -250,7 +250,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: true

Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Version 6.0.5 (2024-07-03)
--------------------------
Stop sending if events fail to be removed from the event store
Add warning for the serialization of data in self-describing event and entity (#898)

Version 6.0.4 (2024-06-12)
--------------------------
Fix CrossDeviceParameterConfiguration constructor to be public (#894) thanks to @thomas-brx
Expand Down
2 changes: 1 addition & 1 deletion Examples
2 changes: 1 addition & 1 deletion SnowplowTracker.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "SnowplowTracker"
s.version = "6.0.4"
s.version = "6.0.5"
s.summary = "Snowplow event tracker for iOS, macOS, tvOS, watchOS for apps and games."
s.description = <<-DESC
Snowplow is a mobile and event analytics platform with a difference: rather than tell our users how they should analyze their data, we deliver their event-level data in their own data warehouse, on their own Amazon Redshift or Postgres database, so they can analyze it any way they choose. Snowplow mobile is used by data-savvy games companies and app developers to better understand their users and how they engage with their games and applications. Snowplow is open source using the business-friendly Apache License, Version 2.0 and scales horizontally to many billions of events.
Expand Down
6 changes: 5 additions & 1 deletion Sources/Core/Emitter/Emitter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ class Emitter: EmitterEventProcessing {
}
let allFailureCount = failedWillRetryCount + failedWontRetryCount

_ = self.eventStore.removeEvents(withIds: removableEvents)
let eventsRemoved = removableEvents.isEmpty ? true : self.eventStore.removeEvents(withIds: removableEvents)

logDebug(message: String(format: "Success Count: %d", successCount))
logDebug(message: String(format: "Failure Count: %d", allFailureCount))
Expand All @@ -366,6 +366,10 @@ class Emitter: EmitterEventProcessing {
if failedWillRetryCount > 0 && successCount == 0 {
logDebug(message: "Ending emitter run as all requests failed.")

self.scheduleStopSending()
} else if !eventsRemoved {
logDebug(message: "Ending emitter run as failed to remove events from event store.")

self.scheduleStopSending()
} else {
self.attemptEmit()
Expand Down
2 changes: 1 addition & 1 deletion Sources/Core/TrackerConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import Foundation

// --- Version
let kSPRawVersion = "6.0.4"
let kSPRawVersion = "6.0.5"
#if os(iOS)
let kSPVersion = "ios-\(kSPRawVersion)"
#elseif os(tvOS)
Expand Down
7 changes: 7 additions & 0 deletions Sources/Snowplow/Events/SelfDescribing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,20 @@ public class SelfDescribing: SelfDescribingAbstract {
self.init(schema: eventData.schema, payload: eventData.data)
}

/// Creates a self-describing event using data represented as an Encodable struct.
/// NOTE: The data should be serializable to JSON using the JSONSerialization class in Foundation. An exception will be thrown if the data is not serializable. To make sure your data is serializable, you can use the `JSONSerialization.isValidJSONObject` function.
/// - Parameters:
/// - schema: A valid schema URI.
/// - payload: Payload for the event.
/// - Returns: A SelfDescribing event.
@objc
public init(schema: String, payload: [String : Any]) {
self._schema = schema
self._payload = payload
}

/// Creates a self-describing event using data represented as an Encodable struct.
/// NOTE: The data should be serializable to JSON using the JSONSerialization class in Foundation. An exception will be thrown if the data is not serializable. To make sure your data is serializable, you can use the `JSONSerialization.isValidJSONObject` function.
/// - Parameters:
/// - schema: A valid schema URI.
/// - data: Data represented using an Encodable struct.
Expand Down
5 changes: 5 additions & 0 deletions Sources/Snowplow/Payload/SelfDescribingJson.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class SelfDescribingJson: NSObject {
}

/// Initializes a newly allocated SPSelfDescribingJson.
/// NOTE: The data should be serializable to JSON using the JSONSerialization class in Foundation. An exception will be thrown if the data is not serializable. To make sure your data is serializable, you can use the `JSONSerialization.isValidJSONObject` function.
/// - Parameters:
/// - schema: A valid schema string.
/// - data: Data to set for data field of the self-describing JSON, should be an NSDictionary.
Expand All @@ -54,6 +55,7 @@ public class SelfDescribingJson: NSObject {
}

/// Initializes a newly allocated SPSelfDescribingJson.
/// NOTE: The data should be serializable to JSON using the JSONSerialization class in Foundation. An exception will be thrown if the data is not serializable. To make sure your data is serializable, you can use the `JSONSerialization.isValidJSONObject` function.
/// - Parameters:
/// - schema: A valid schema string.
/// - data: Dictionary to set for data field of the self-describing JSON.
Expand All @@ -64,6 +66,7 @@ public class SelfDescribingJson: NSObject {
}

/// Initializes a newly allocated SPSelfDescribingJson.
/// NOTE: The payload should be serializable to JSON using the JSONSerialization class in Foundation. An exception will be thrown if the data is not serializable. To make sure your data is serializable, you can use the `JSONSerialization.isValidJSONObject` function.
/// - Parameters:
/// - schema: A valid schema string.
/// - data: Payload to set for data field of the self-describing JSON.
Expand All @@ -74,6 +77,7 @@ public class SelfDescribingJson: NSObject {
}

/// Initializes a newly allocated SPSelfDescribingJson.
/// NOTE: The data should be serializable to JSON using the JSONSerialization class in Foundation. An exception will be thrown if the data is not serializable. To make sure your data is serializable, you can use the `JSONSerialization.isValidJSONObject` function.
/// - Parameters:
/// - schema: A valid schema URI.
/// - data: Self-describing JSON to set for data field of the self-describing JSON.
Expand Down Expand Up @@ -104,6 +108,7 @@ public class SelfDescribingJson: NSObject {
}

/// Sets the data field of the self-describing JSON.
/// NOTE: The data should be serializable to JSON using the JSONSerialization class in Foundation. An exception will be thrown if the data is not serializable. To make sure your data is serializable, you can use the `JSONSerialization.isValidJSONObject` function.
/// - Parameter data: A self-describing JSON to be nested into the data.
@objc
public func setData(withSelfDescribingJson data: SelfDescribingJson) {
Expand Down
19 changes: 17 additions & 2 deletions Tests/TestEmitter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,26 @@ class TestEmitter: XCTestCase {

flush(emitter)
}

func testPausesEmitIfFailedToRemoveFromEventStore() {
let networkConnection = MockNetworkConnection(requestOption: .post, statusCode: 200)
let mockStore = MockEventStore()
mockStore.failToRemoveEvents = true
let emitter = self.emitter(with: networkConnection, bufferOption: .single, eventStore: mockStore)

addPayload(generatePayloads(1).first!, emitter)
Thread.sleep(forTimeInterval: 0.5)
addPayload(generatePayloads(1).first!, emitter)
Thread.sleep(forTimeInterval: 0.5)

XCTAssertEqual(1, networkConnection.sendingCount)
XCTAssertEqual(2, mockStore.count())
}

// MARK: - Emitter builder

func emitter(with networkConnection: NetworkConnection, bufferOption: BufferOption = .single) -> Emitter {
let emitter = Emitter(networkConnection: networkConnection, namespace: "ns1", eventStore: MockEventStore()) { emitter in
func emitter(with networkConnection: NetworkConnection, bufferOption: BufferOption = .single, eventStore: EventStore = MockEventStore()) -> Emitter {
let emitter = Emitter(networkConnection: networkConnection, namespace: "ns1", eventStore: eventStore) { emitter in
emitter.bufferOption = bufferOption
emitter.emitRange = 200
emitter.byteLimitGet = 20000
Expand Down
31 changes: 22 additions & 9 deletions Tests/Utils/MockEventStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class MockEventStore: NSObject, EventStore {

var db: [Int64 : Payload] = [:]
var lastInsertedRow = 0
var failToRemoveEvents = false

override init() {
super.init()
Expand All @@ -32,22 +33,34 @@ class MockEventStore: NSObject, EventStore {
}

func removeEvent(withId storeId: Int64) -> Bool {
logVerbose(message: "Remove \(storeId)")
return db.removeValue(forKey: storeId) != nil
if failToRemoveEvents {
return false
} else {
logVerbose(message: "Remove \(storeId)")
return db.removeValue(forKey: storeId) != nil
}
}

func removeEvents(withIds storeIds: [Int64]) -> Bool {
let result = true
for storeId in storeIds {
db.removeValue(forKey: storeId)
if failToRemoveEvents {
return false
} else {
let result = true
for storeId in storeIds {
db.removeValue(forKey: storeId)
}
return result
}
return result
}

func removeAllEvents() -> Bool {
db.removeAll()
lastInsertedRow = -1
return true
if failToRemoveEvents {
return false
} else {
db.removeAll()
lastInsertedRow = -1
return true
}
}

func count() -> UInt {
Expand Down

0 comments on commit 18f62a1

Please sign in to comment.