-
Notifications
You must be signed in to change notification settings - Fork 11
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
ALTAPPS-1323: Shared research analytic logging issue #1145
Merged
ivan-magda
merged 7 commits into
develop
from
feature/ALTAPPS-1323/Shared-research-analytic-logging-issue
Aug 7, 2024
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ee573c2
Make AnalyticActionDispatcherConfig a more generic CompletableCorouti…
XanderZhu db53f4e
Add CompletableCoroutineActionDispatcher test
XanderZhu 0f595eb
Save events back to the cache in case of failed log request
XanderZhu 19da821
Merge branch 'refs/heads/develop' into feature/ALTAPPS-1323/Shared-re…
XanderZhu 7aa9fcc
Rename CompletableActionDispatcherTest
XanderZhu 7be28c8
Refactor ViewStepActionDispatcher
XanderZhu 5d62450
Merge branch 'develop' into feature/ALTAPPS-1323/Shared-research-anal…
ivan-magda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
71 changes: 0 additions & 71 deletions
71
...rc/commonMain/kotlin/org/hyperskill/app/analytic/presentation/AnalyticActionDispatcher.kt
This file was deleted.
Oops, something went wrong.
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
64 changes: 64 additions & 0 deletions
64
...nMain/kotlin/org/hyperskill/app/core/presentation/CompletableCoroutineActionDispatcher.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,64 @@ | ||
package org.hyperskill.app.core.presentation | ||
|
||
import kotlinx.coroutines.CompletableJob | ||
import kotlinx.coroutines.CoroutineExceptionHandler | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.Job | ||
import kotlinx.coroutines.SupervisorJob | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.plus | ||
import org.hyperskill.app.analytic.domain.model.AnalyticEvent | ||
import ru.nobird.app.presentation.redux.dispatcher.ActionDispatcher | ||
|
||
/** | ||
* Base class for ActionDispatcher dispatching actions, that should not be cancelled with feature cancellation. | ||
* E.g. analytic event logging. | ||
* | ||
* @param coroutineScope is not cancelled on [cancel]. | ||
* Instead it is complete to wait for all launched coroutines to finish. | ||
*/ | ||
internal abstract class CompletableCoroutineActionDispatcher<Action, Message>( | ||
private val coroutineScope: CoroutineScope | ||
) : ActionDispatcher<Action, Message> { | ||
|
||
private var isCancelled: Boolean = false | ||
|
||
abstract suspend fun handleNonCancellableAction(action: Action) | ||
|
||
override fun handleAction(action: Action) { | ||
if (isCancelled) return | ||
|
||
coroutineScope.launch { | ||
handleNonCancellableAction(action) | ||
} | ||
} | ||
|
||
override fun setListener(listener: (message: Message) -> Unit) { | ||
// no op | ||
} | ||
|
||
override fun cancel() { | ||
isCancelled = true | ||
(coroutineScope.coroutineContext[Job] as? CompletableJob)?.complete() | ||
} | ||
|
||
/** | ||
* Represents [CoroutineScope] config for logging [AnalyticEvent]. | ||
* If [parentScope] is not presented uses a [Dispatchers.Main].immediate + [SupervisorJob]. | ||
*/ | ||
interface ScopeConfigOptions { | ||
val parentScope: CoroutineScope? | ||
|
||
val coroutineExceptionHandler: CoroutineExceptionHandler | ||
|
||
fun createScope(): CoroutineScope { | ||
val parentScope = parentScope | ||
return if (parentScope != null) { | ||
parentScope + SupervisorJob(parentScope.coroutineContext[Job]) + coroutineExceptionHandler | ||
} else { | ||
CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate + coroutineExceptionHandler) | ||
} | ||
} | ||
} | ||
} |
10 changes: 5 additions & 5 deletions
10
...ntation/AnalyticActionDispatcherConfig.kt → ...letableCoroutineActionDispatcherConfig.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
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I suppose that there is a case where the current user profile can be changed between
logEvent
, and old analytic events can revert to being associated with the previous user profile.However, it is not so critical right now.
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.
@ivan-magda
Yes, you are right. Good point to think about.