Skip to content

Update the Event Flushing Mechanism to save in disk #10

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

CoderGamester
Copy link
Contributor

@CoderGamester CoderGamester commented Feb 8, 2025

Update the Event Flushing Mechanism to avoid losing events due to network issues or game being closed

  • Add the option to save events to disk if they failed to be sent when the game loses focus on the device screen.
  • Disable sending events if application is offline
  • Added Task return to allow methods to await for event flushing to be done. This is useful in the case events fail and are needed to save localy

Reasoning

  • I noticed that the SDK doesn't have "offline" or "lose connection" mode this means that failed events would never be sent if the device lose connection at the end of the session or the player plays the entire session offline
  • This is not optimal for mobile games or low stable network devices

@CoderGamester
Copy link
Contributor Author

bump to merge

@@ -103,7 +103,7 @@ public static void OnApplicationFocus(bool hasFocus)
}
else
{
Flush();
_dispatcher.FlushOrSaveToDisk();
StopPolling();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we need to make this return a Task as well:

public static Task Flush()
{
     return _dispatcher.Flush();
}

Also I think we should avoid async void methods, eg:

private static async void StartPolling(int flushTimer)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flush already return a Task
And I do agree that we need to avoid async void.

The goal of this PR is to keep changes to a minimal

@@ -42,7 +49,7 @@ private void Enqueue(List<Event> data)
_events.Enqueue(eventData);
}

public async void Flush()
public async Task Flush()
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm concerned we don't have any kind of thread safety mechanism on the Flush method


namespace AptabaseSDK
{
public class WebGLDispatcher: IDispatcher
{
private const string EVENT_ENDPOINT = "/api/v0/event";
private const string APTABASE_KEY = "aptabase_key";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a better name for this key, eg aptabase_events_cache?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants