-
Notifications
You must be signed in to change notification settings - Fork 369
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
[5.0.0] Fix outcome requests #1793
Conversation
* Add `sessionTime` as an additional property to an `OutcomeEvent` object * This is for the influenced session ending outcomes that send session_time to the outcomes endpoint * For `OutcomeEventParams` constructor, don't make the parameter `timestamp` optional, so not to confuse with other parameters when instantiating an instance
* Create separate outcome-related method `sendSessionEndOutcomeEvent` * We were also sending session_time in ms, but it should be seconds.
* Update database version to v9 and make migration. * I default this new `session_time` to a value of `1` instead of `0` intentionally to work around an issue from the v5.0.0-beta's for migration's sake and get these outcomes migrated, sent, and done with. * When outcome requests fail, they are cached for retrying. The v5.0.0-beta's likely encountered failure responses and cached these. If there are cached `os__session_duration` outcomes and we send them off with zero session_time, the server will keep sending us a failure response. So, let's just send a time of 1 second.
@@ -7,7 +7,8 @@ internal class OutcomeEventParams constructor( | |||
val outcomeId: String, | |||
val outcomeSource: OutcomeSource?, // This field is optional | |||
var weight: Float, // This field is optional. | |||
var timestamp: Long = 0, | |||
var sessionTime: Long, // This field is optional | |||
var timestamp: Long, |
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.
timestamp
previously set its default value to 0. Was removing this default intentional?
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.
Yes it was intentional, it was briefly mentioned in a commit but here is more information about why I changed it.
The SDK actually always passed in a value for timestamp
to the OutcomeEventParams
constructor, so this default was not needed. In addition, it was not to confuse with the new sessionTime
parameter. After adding sessionTime
to the constructor, the app and unit tests built because the argument we used to pass for timestamp
is now interpreted as sessionTime
and sessionTime
started defaulting to 0
.
But I think it is a good note what this parameter means, that it starts out 0
until it fails and becomes cached.
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.
Reviewed 7 of 8 files at r1, 9 of 9 files at r2, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @jennantilla, @jkasten2, and @shepherd-l)
* When an outcome is created, its `timestamp` should start out as zero. * When the outcome request is sent and fails, the SDK will save and retry the outcome, then it will save the current `timestamp` for future sending
[5.0.0] Fix outcome requests
[5.0.0] Fix outcome requests
[5.0.0] Fix outcome requests
Description
One Line Summary
Fix outcome request payload to include
device_type
andsession_time
(if the outcome type isos__session_duration
).Details
Motivation
The outcomes endpoint expects
device_type
to be in the request body but we were not sending it, and we receive a 400 error in response. Now, we will always sendtype
in thesubscription
data.The second problem this PR addresses is for influenced session ending outcomes, the server expects a non-zero value for
session_time
to be in the request body if the outcome has an ID ofos__session_duration
. However, we were not sendingsession_time
and receive a 400 error response"There was a problem in the JSON you submitted","\"session_time\" must be positive when submitting os__session_duration"
. Now, we sill send anos__session_duration
outcome withsession_time
if the session that just ended is attributed.Another detail is that failed outcome requests keep the outcome in the cache (database) so that they are re-sent on the next app start.
Note that before, we were sending a
os__session_duration
outcome with no influences when a session that just ended is unattributed. We will no longer do this, but these outcomes may be cached and need to be addressed.The
session_time
that we were sending to update user endpoint was actually in milliseconds, and this is fixed in this PR to be seconds, which is what the server expects.To make the minimal amount of changes, I added a
session_time
property toOutcomeEvent
and a new column to the outcomes table. Not all outcomes will utilizesession_time
if these areaddOutcome
methods.Scope
session_time
.session_time
of1
just to get them successfully sent and done with, even though thissession_time
may not be accurate. Otherwise, they may keep staying in the cache and retrying.Details about Commits Below
1. Add device type to the outcome event request
2. Add session_time to OutcomeEvent
sessionTime
as an additional property to anOutcomeEvent
objectOutcomeEventParams
constructor, don't make the parametertimestamp
optional, so not to confuse with other parameters when instantiating an instance3. Send influenced session outcome
sendSessionEndOutcomeEvent
4. update outcomes table to include session_time column
session_time
to a value of1
instead of0
intentionally to work around an issue from the v5.0.0-beta's for migration's sake and get these outcomes migrated, sent, and done with.os__session_duration
outcomes and we send them off with zero session_time, the server will keep sending us a failure response. So, let's just send a time of 1 second.Testing
Unit testing
Manual testing
Tested on Pixel emulator on API 30.
session_time
of1
added, successful response, and be removed from the outcomes tableAffected code checklist
Checklist
Overview
Testing
Final pass
This change is