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

fix: update last session timestamp #437

Merged
merged 1 commit into from
May 29, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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