-
Notifications
You must be signed in to change notification settings - Fork 32
support enable/disable analytics #169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
fb57545
da7481f
4cec3ee
deb2f63
cedd664
98afe6d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,9 +27,9 @@ internal class EventPipeline( | |
var apiHost: String = Constants.DEFAULT_API_HOST | ||
) { | ||
|
||
private val writeChannel: Channel<BaseEvent> | ||
private var writeChannel: Channel<BaseEvent> | ||
|
||
private val uploadChannel: Channel<String> | ||
private var uploadChannel: Channel<String> | ||
|
||
private val httpClient: HTTPClient = HTTPClient(apiKey) | ||
|
||
|
@@ -64,20 +64,30 @@ internal class EventPipeline( | |
} | ||
|
||
fun start() { | ||
if (running) return | ||
running = true | ||
|
||
// avoid to re-establish a channel if the pipeline just gets created | ||
if (writeChannel.isClosedForSend || writeChannel.isClosedForReceive) { | ||
writeChannel = Channel(UNLIMITED) | ||
uploadChannel = Channel(UNLIMITED) | ||
} | ||
Comment on lines
+71
to
+74
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we use a new channel is possible we leave messages that are stuck in the pipe and loose them when we create a new pipe? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah. that's possible. but we're using the only workaround is not to close/cancel channel at all, but that increases the complexity, since we would have to distinguish pause vs stop. if stop, we would want to close anything ongoing completely, for example on application shutdown. |
||
|
||
schedule() | ||
write() | ||
upload() | ||
} | ||
|
||
fun stop() { | ||
if (!running) return | ||
running = false | ||
|
||
uploadChannel.cancel() | ||
writeChannel.cancel() | ||
unschedule() | ||
running = false | ||
} | ||
|
||
fun stringifyBaseEvent(payload: BaseEvent): String { | ||
internal fun stringifyBaseEvent(payload: BaseEvent): String { | ||
val finalPayload = EncodeDefaultsJson.encodeToJsonElement(payload) | ||
.jsonObject.filterNot { (k, v) -> | ||
// filter out empty userId and traits values | ||
|
@@ -186,7 +196,6 @@ internal class EventPipeline( | |
| msg=${e.message} | ||
""".trimMargin(), kind = LogKind.ERROR | ||
) | ||
e.printStackTrace() | ||
} | ||
|
||
return shouldCleanup | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use "it" instead of "uri" to keep consistent?