Skip to content

Commit

Permalink
[sdk 396] Event Q emptying into RQ issue fixed (#110)
Browse files Browse the repository at this point in the history
* Production Issue fixed

* Update CHANGELOG.md

* Update CHANGELOG.md

Co-authored-by: ArtursKadikis <[email protected]>
  • Loading branch information
ZahidZafar and ArtursKadikis authored Jun 10, 2021
1 parent b857c0e commit 782e650
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 63 deletions.
2 changes: 1 addition & 1 deletion Assets/Plugins/CountlySDK/Helpers/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace Plugins.CountlySDK.Helpers
{
internal class Constants
{
public const string SdkVersion = "20.11.2";
public const string SdkVersion = "20.11.3";

#if UNITY_EDITOR
public const string SdkName = "csharp-unity-editor";
Expand Down
16 changes: 6 additions & 10 deletions Assets/Plugins/CountlySDK/Helpers/RequestCountlyHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal RequestCountlyHelper(CountlyConfiguration config, CountlyLogHelper log,
_requestRepo = requestRepo;
}

private async Task AddRequestToQueue(CountlyRequestModel request)
private void AddRequestToQueue(CountlyRequestModel request)
{

Log.Verbose("[RequestCountlyHelper] AddRequestToQueue: " + request.ToString());
Expand All @@ -47,8 +47,6 @@ private async Task AddRequestToQueue(CountlyRequestModel request)
}

_requestRepo.Enqueue(request);

await ProcessQueue();
}

internal async Task ProcessQueue()
Expand Down Expand Up @@ -151,12 +149,10 @@ internal string BuildPostRequest(Dictionary<string, object> queryParams)
}

/// <summary>
/// Uses GetAsync/PostAsync method to make request to the Countly server and returns the response.
/// An internal function to add a request to request queue.
/// </summary>
/// <param name="url"></param>
/// <param name="postData"></param>
/// <returns></returns>
internal async Task GetResponseAsync(Dictionary<string, object> queryParams)

internal void AddToRequestQueue(Dictionary<string, object> queryParams)
{
CountlyRequestModel requestModel;
string data = BuildPostRequest(queryParams);
Expand All @@ -166,7 +162,7 @@ internal async Task GetResponseAsync(Dictionary<string, object> queryParams)
requestModel = new CountlyRequestModel(true, BuildGetRequest(queryParams), null, DateTime.UtcNow);
}

await AddRequestToQueue(requestModel);
AddRequestToQueue(requestModel);
}

/// <summary>
Expand Down Expand Up @@ -244,4 +240,4 @@ private async Task<CountlyResponse> PostAsync(string uri, string data)
}

}
}
}
5 changes: 3 additions & 2 deletions Assets/Plugins/CountlySDK/Services/ConsentCountlyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ internal async Task SendConsentChanges(List<Consents> consents, bool value)
}
};

await _requestCountlyHelper.GetResponseAsync(requestParams);
_requestCountlyHelper.AddToRequestQueue(requestParams);
await _requestCountlyHelper.ProcessQueue();
}
#endregion

Expand Down Expand Up @@ -349,4 +350,4 @@ private void NotifyListeners(List<Consents> updatedConsents, bool newConsentValu
internal override void DeviceIdChanged(string deviceId, bool merged) { }
#endregion
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ internal async Task SendCrashReportInternal(CountlyExceptionDetailModel model)
}
};

await _requestCountlyHelper.GetResponseAsync(requestParams);
_requestCountlyHelper.AddToRequestQueue(requestParams);
await _requestCountlyHelper.ProcessQueue();

}

Expand Down Expand Up @@ -170,4 +171,4 @@ internal override void DeviceIdChanged(string deviceId, bool merged)
}
#endregion
}
}
}
7 changes: 5 additions & 2 deletions Assets/Plugins/CountlySDK/Services/DeviceIdCountlyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public async Task ChangeDeviceIdWithoutMerge(string deviceId)
}

//Add currently recorded events to request queue-----------------------------------
await _eventCountlyService.AddEventsToRequestQueue();
_eventCountlyService.AddEventsToRequestQueue();

//Ends current session
//Do not dispose timer object
Expand All @@ -122,6 +122,8 @@ public async Task ChangeDeviceIdWithoutMerge(string deviceId)
}

NotifyListeners(false);

await _requestCountlyHelper.ProcessQueue();
}

/// <summary>
Expand Down Expand Up @@ -176,7 +178,8 @@ public async Task ChangeDeviceIdWithMerge(string deviceId)
{ "old_device_id", oldDeviceId }
};

await _requestCountlyHelper.GetResponseAsync(requestParams);
_requestCountlyHelper.AddToRequestQueue(requestParams);
await _requestCountlyHelper.ProcessQueue();
NotifyListeners(true);
}

Expand Down
41 changes: 10 additions & 31 deletions Assets/Plugins/CountlySDK/Services/EventCountlyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ internal EventCountlyService(CountlyConfiguration configuration, CountlyLogHelpe
/// <summary>
/// Add all recorded events to request queue
/// </summary>
internal async Task AddEventsToRequestQueue()
internal void AddEventsToRequestQueue()
{

Log.Debug("[EventCountlyService] AddEventsToRequestQueue");
Log.Debug("[EventCountlyService] AddEventsToRequestQueue Start");

if (_eventRepo.Models.Count == 0) {
return;
}


int count = _eventRepo.Models.Count;
//Send all at once
Dictionary<string, object> requestParams =
new Dictionary<string, object>
Expand All @@ -47,10 +47,11 @@ internal async Task AddEventsToRequestQueue()
}
};

await _requestCountlyHelper.GetResponseAsync(requestParams);

_eventRepo.Clear();
_requestCountlyHelper.AddToRequestQueue(requestParams);

for (int i = 0; i < count; ++i) {
_eventRepo.Dequeue();
}
}

/// <summary>
Expand All @@ -70,7 +71,8 @@ internal async Task RecordEventAsync(CountlyEventModel @event)
_eventRepo.Enqueue(@event);

if (_eventRepo.Count >= _configuration.EventQueueThreshold) {
await AddEventsToRequestQueue();
AddEventsToRequestQueue();
await _requestCountlyHelper.ProcessQueue();
}
}

Expand Down Expand Up @@ -145,29 +147,6 @@ public async Task RecordEventAsync(string key, IDictionary<string, object> segme
await RecordEventAsync(@event);
}

/// <summary>
/// Sends multiple events to the countly server. It expects a list of events as input.
/// </summary>
/// <param name="events">a list of events</param>
/// <returns></returns>
internal async Task ReportMultipleEventsAsync(List<CountlyEventModel> events)
{
if (events == null || events.Count == 0) {
return;
}

Dictionary<string, object> requestParams =
new Dictionary<string, object>
{
{
"events", JsonConvert.SerializeObject(events, Formatting.Indented,
new JsonSerializerSettings {NullValueHandling = NullValueHandling.Ignore})
}
};

await _requestCountlyHelper.GetResponseAsync(requestParams);
}

/// <summary>
/// Reports a custom event to the Countly server.
/// </summary>
Expand Down Expand Up @@ -230,4 +209,4 @@ internal override void ConsentChanged(List<Consents> updatedConsents, bool newCo
}
#endregion
}
}
}
8 changes: 5 additions & 3 deletions Assets/Plugins/CountlySDK/Services/LocationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ internal async Task SendRequestWithEmptyLocation()
{ "location", string.Empty }
};

await _requestCountlyHelper.GetResponseAsync(requestParams);
_requestCountlyHelper.AddToRequestQueue(requestParams);
await _requestCountlyHelper.ProcessQueue();
}

/// <summary>
Expand Down Expand Up @@ -85,7 +86,8 @@ internal async Task SendIndependantLocationRequest()
}

if (requestParams.Count > 0) {
await _requestCountlyHelper.GetResponseAsync(requestParams);
_requestCountlyHelper.AddToRequestQueue(requestParams);
await _requestCountlyHelper.ProcessQueue();
}
}

Expand Down Expand Up @@ -183,4 +185,4 @@ internal override void ConsentChanged(List<Consents> updatedConsents, bool newCo
}
#endregion
}
}
}
5 changes: 3 additions & 2 deletions Assets/Plugins/CountlySDK/Services/PushCountlyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ private async Task PostToCountlyAsync(TestMode? mode, string token)
{ $"{Constants.UnityPlatform}_token", token },
};

await _requestCountlyHelper.GetResponseAsync(requestParams);
_requestCountlyHelper.AddToRequestQueue(requestParams);
await _requestCountlyHelper.ProcessQueue();
}

/// <summary>
Expand Down Expand Up @@ -147,4 +148,4 @@ public IDictionary<string, object> ToDictionary()
}

}
}
}
17 changes: 10 additions & 7 deletions Assets/Plugins/CountlySDK/Services/SessionCountlyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private async void SessionTimerOnElapsedAsync(object sender, ElapsedEventArgs el
{
Log.Debug("[SessionCountlyService] SessionTimerOnElapsedAsync");

await _eventService.AddEventsToRequestQueue();
_eventService.AddEventsToRequestQueue();
await _requestCountlyHelper.ProcessQueue();

if (!_configuration.IsAutomaticSessionTrackingDisabled) {
Expand Down Expand Up @@ -142,7 +142,8 @@ the SDK adds an empty location entry to every "begin_session" request. */
requestParams.Add("metrics", JsonConvert.SerializeObject(CountlyMetricModel.Metrics, Formatting.Indented,
new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }));

await _requestCountlyHelper.GetResponseAsync(requestParams);
_requestCountlyHelper.AddToRequestQueue(requestParams);
await _requestCountlyHelper.ProcessQueue();
}

/// <summary>
Expand All @@ -163,17 +164,18 @@ internal async Task EndSessionAsync()

IsSessionInitiated = false;

await _eventService.AddEventsToRequestQueue();
_eventService.AddEventsToRequestQueue();

Dictionary<string, object> requestParams =
new Dictionary<string, object>
{
{"end_session", 1},
{"session_duration", (DateTime.Now - _lastSessionRequestTime).TotalSeconds}
};


await _requestCountlyHelper.GetResponseAsync(requestParams);

_requestCountlyHelper.AddToRequestQueue(requestParams);
await _requestCountlyHelper.ProcessQueue();
}


Expand Down Expand Up @@ -203,7 +205,8 @@ internal async Task ExtendSessionAsync()

_lastSessionRequestTime = DateTime.Now;

await _requestCountlyHelper.GetResponseAsync(requestParams);
_requestCountlyHelper.AddToRequestQueue(requestParams);
await _requestCountlyHelper.ProcessQueue();

}

Expand All @@ -225,4 +228,4 @@ internal override async void ConsentChanged(List<Consents> updatedConsents, bool
}
#endregion
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ public async Task SetUserDetailsAsync(CountlyUserDetailsModel userDetailsModel)
new JsonSerializerSettings{ NullValueHandling = NullValueHandling.Ignore }) },
};

await _requestCountlyHelper.GetResponseAsync(requestParams);
_requestCountlyHelper.AddToRequestQueue(requestParams);
await _requestCountlyHelper.ProcessQueue();
}

/// <summary>
Expand Down Expand Up @@ -129,7 +130,8 @@ public async Task SetCustomUserDetailsAsync(CountlyUserDetailsModel userDetailsM
})
}
};
await _requestCountlyHelper.GetResponseAsync(requestParams);
_requestCountlyHelper.AddToRequestQueue(requestParams);
await _requestCountlyHelper.ProcessQueue();
}

/// <summary>
Expand Down Expand Up @@ -309,4 +311,4 @@ internal override void ConsentChanged(List<Consents> updatedConsents, bool newCo
}
#endregion
}
}
}
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 20.11.3
* Fixed potential timing issues in situations where events are combined into a request.

## 20.11.2
* Added Consent feature
* Added data type checking for segmentation
Expand Down

0 comments on commit 782e650

Please sign in to comment.