-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'coroutines' into get_add_key_coroutines
- Loading branch information
Showing
11 changed files
with
183 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
parsely/src/main/java/com/parsely/parselyandroid/FlushQueue.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.parsely.parselyandroid | ||
|
||
import com.parsely.parselyandroid.JsonSerializer.toParselyEventsPayload | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.sync.Mutex | ||
import kotlinx.coroutines.sync.withLock | ||
|
||
internal class FlushQueue( | ||
private val flushManager: FlushManager, | ||
private val repository: QueueRepository, | ||
private val restClient: RestClient, | ||
private val scope: CoroutineScope | ||
) { | ||
|
||
private val mutex = Mutex() | ||
|
||
operator fun invoke(skipSendingEvents: Boolean) { | ||
scope.launch { | ||
mutex.withLock { | ||
val eventsToSend = repository.getStoredQueue() | ||
|
||
if (eventsToSend.isEmpty()) { | ||
flushManager.stop() | ||
return@launch | ||
} | ||
|
||
if (skipSendingEvents) { | ||
ParselyTracker.PLog("Debug mode on. Not sending to Parse.ly. Otherwise, would sent ${eventsToSend.size} events") | ||
repository.remove(eventsToSend) | ||
return@launch | ||
} | ||
ParselyTracker.PLog("Sending request with %d events", eventsToSend.size) | ||
val jsonPayload = toParselyEventsPayload(eventsToSend) | ||
ParselyTracker.PLog("POST Data %s", jsonPayload) | ||
ParselyTracker.PLog("Requested %s", ParselyTracker.ROOT_URL) | ||
restClient.send(jsonPayload) | ||
.fold( | ||
onSuccess = { | ||
ParselyTracker.PLog("Pixel request success") | ||
repository.remove(eventsToSend) | ||
}, | ||
onFailure = { | ||
ParselyTracker.PLog("Pixel request exception") | ||
ParselyTracker.PLog(it.toString()) | ||
} | ||
) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 0 additions & 18 deletions
18
parsely/src/main/java/com/parsely/parselyandroid/SdkInit.kt
This file was deleted.
Oops, something went wrong.
57 changes: 0 additions & 57 deletions
57
parsely/src/main/java/com/parsely/parselyandroid/SendEvents.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.