Skip to content

Commit

Permalink
[WIP] Send eval context in events
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziodemaria committed Mar 27, 2024
1 parent a4976a2 commit d2f805a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion ConfidenceDemoApp/ConfidenceDemoApp/ConfidenceDemoApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ extension ConfidenceDemoApp {

// NOTE: Using a random UUID for each app start is not advised and can result in getting stale values.
let ctx = MutableContext(targetingKey: UUID.init().uuidString, structure: MutableStructure())
OpenFeatureAPI.shared.setProvider(provider: provider, initialContext: ctx)
Task {
await OpenFeatureAPI.shared.setProviderAndWait(provider: provider, initialContext: ctx)
confidence.send(eventName: "my_event")
}
}
}
2 changes: 1 addition & 1 deletion Sources/Confidence/Confidence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class Confidence: ConfidenceEventSender {
}

public func send(eventName: String) {
print("Sending \(eventName)")
print("Sending \(eventName) - Targeting key: \(context["targeting_key"] ?? "UNKNOWN")")
}

public func updateContextEntry(key: String, value: String) {
Expand Down
3 changes: 3 additions & 0 deletions Sources/ConfidenceProvider/ConfidenceFeatureProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class ConfidenceFeatureProvider: FeatureProvider {
}

if self.initializationStrategy == .activateAndFetchAsync {
confidence?.context = ["targeting_key": "CACHED"]
eventHandler.send(.ready)
}

Expand All @@ -70,6 +71,7 @@ public class ConfidenceFeatureProvider: FeatureProvider {

// signal the provider is ready after the network request is done
if self.initializationStrategy == .fetchAndActivate {
confidence?.context = ["targeting_key": initialContext.getTargetingKey()]
eventHandler.send(.ready)
}
} catch {
Expand Down Expand Up @@ -111,6 +113,7 @@ public class ConfidenceFeatureProvider: FeatureProvider {
// update the storage
try await store(with: newContext, resolveResult: resolveResult, refreshCache: true)
eventHandler.send(ProviderEvent.ready)
confidence?.context = ["targeting_key": newContext.getTargetingKey()]
} catch {
eventHandler.send(ProviderEvent.ready)
// do nothing
Expand Down

0 comments on commit d2f805a

Please sign in to comment.