Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Commit

Permalink
fix: update last session timestamp (#437)
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto authored May 29, 2020
1 parent 696fe66 commit fb250f7
Showing 1 changed file with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;

final class LifecycleWatcher implements DefaultLifecycleObserver {

private long lastStartedSession = 0L;
private final AtomicLong lastUpdatedSession = new AtomicLong(0L);

private final long sessionIntervalMillis;

Expand Down Expand Up @@ -64,15 +66,18 @@ public void onStart(final @NotNull LifecycleOwner owner) {

private void startSession() {
if (enableSessionTracking) {
final long currentTimeMillis = currentDateProvider.getCurrentTimeMillis();
cancelTask();
if (lastStartedSession == 0L
|| (lastStartedSession + sessionIntervalMillis) <= currentTimeMillis) {

final long currentTimeMillis = currentDateProvider.getCurrentTimeMillis();
final long lastUpdatedSession = this.lastUpdatedSession.get();

if (lastUpdatedSession == 0L
|| (lastUpdatedSession + sessionIntervalMillis) <= currentTimeMillis) {
addSessionBreadcrumb("start");
hub.startSession();
runningSession.set(true);
}
lastStartedSession = currentTimeMillis;
this.lastUpdatedSession.set(currentTimeMillis);
}
}

Expand All @@ -81,6 +86,9 @@ private void startSession() {
@Override
public void onStop(final @NotNull LifecycleOwner owner) {
if (enableSessionTracking) {
final long currentTimeMillis = currentDateProvider.getCurrentTimeMillis();
this.lastUpdatedSession.set(currentTimeMillis);

scheduleEndSession();
}

Expand Down

0 comments on commit fb250f7

Please sign in to comment.