Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Handling events not sent to Adobe Analytics because of internet unavailability#14259

Open
SnchitGrover wants to merge 10 commits intoadobe:masterfrom
SnchitGrover:master
Open

Handling events not sent to Adobe Analytics because of internet unavailability#14259
SnchitGrover wants to merge 10 commits intoadobe:masterfrom
SnchitGrover:master

Conversation

@SnchitGrover
Copy link
Copy Markdown
Contributor

No description provided.

@SnchitGrover
Copy link
Copy Markdown
Contributor Author

@vickramdhawal @swmitra

@SnchitGrover SnchitGrover changed the title Handling events not sent to Adobe Analytics because of internet unavailability <WIP Do not Merge>Handling events not sent to Adobe Analytics because of internet unavailability Apr 25, 2018
@swmitra
Copy link
Copy Markdown
Collaborator

swmitra commented Apr 25, 2018

Good start @SnchitGrover.


unsentEventFileLocation.exists(function (err, exists) {
if (err) {
console.log("absdjasd");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Log appropriate message. Also if an error occurs the eventParams can still be sent to for logging since internet is available.

} else {
if(exists) {
FileUtils.readAsText(unsentEventFileLocation).done(function (content) {
FileUtils.writeText(unsentEventFileLocation, "", true).done(function () {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The log file should be cleared only if the data is successfully uploaded.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If I clear the log file as soon as I successfully read it and then if there is any failure I can write those back to log file?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

you will have to implement a new shell api readAndClearFile to achieve this else there will always be a synchronisation problem.

sendAnalyticsDataToServer(analyticsData, eventParams).done(function () {
result.resolve();
}).fail(function (err) {
result.reject();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

if upload fails, log the data to the unsentEventFileLocation

result.reject();
});
}).fail(function (err) {
result.reject();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If file read fails try to send the current data to the server else this will also be lost.

function sendAnalyticsDataToServer (analyticsData, eventParams) {
var result = new $.Deferred();

analyticsData.push(getAnalyticsData(eventParams));
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

get a single parameter of analyticsData for this method. Push the eventParams before invoking this method.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I am doing this to maintain the order, if I don't do this user action to "cancel" "auto-update" would have a timestamp less than "auto-update" "render" event.


function internetAvailableSendAllEvents(unsentEventFileLocation, eventParams) {
var result = new $.Deferred();
var analyticsData = [];
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

populate the analyticsData with eventParams here itself. It will just be more consistent. This may not be desired if the ordering of events in the array makes a difference.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We should try to maintain the event order.

if(exists) {
FileUtils.readAsText(unsentEventFileLocation).done(function (content) {
FileUtils.writeText(unsentEventFileLocation, "", true).done(function () {
result.resolve(true);
Copy link
Copy Markdown
Collaborator

@vickramdhawal vickramdhawal Apr 26, 2018

Choose a reason for hiding this comment

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

what does this "true" signify ?

}
});
sendAnalyticsDataToServer(analyticsData, eventParams).done(function () {
result.resolve();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

with the current code the result promise will get resolved twice. once when the files is cleared and once here once the data is uploaded.


unsentEventFileLocation.exists(function (err, fileExists) {
if (err) {
result.reject();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

log the error for debugging purposes.

PreferencesManager.setViewState("nextHealthDataSendTime", currentTime + ONE_DAY);
sendHealthDataToServer().always(function() {
sendAnalyticsDataToServer()
sendAnalyticsDataToServerIfInternetAvailableElseLogtoLocalFile()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

simply call it sendAnalyticsData or sendOrSaveAnalyticsData if you feel that information is relevant. The implementation is not open for the client so simply sendAnalyticsData should also be sufficient.

@vickramdhawal
Copy link
Copy Markdown
Collaborator

@SnchitGrover You will also need to sign the CLA before the changes can be merged. http://dev.brackets.io/brackets-contributor-license-agreement.html

} else {
if(exists) {
FileUtils.readAsText(unsentEventFileLocation).done(function (content) {
FileUtils.writeText(unsentEventFileLocation, "", true).done(function () {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

you will have to implement a new shell api readAndClearFile to achieve this else there will always be a synchronisation problem.

} else {
if(exists) {
FileUtils.readAsText(unsentEventFileLocation).done(function (content) {
FileUtils.writeText(unsentEventFileLocation, "", true);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

issue of multiple reads is still not resolved.

var unsentEventFileLocation = FileSystem.getFileForPath(brackets.app.getApplicationSupportDirectory() + "/unsentEventFile.txt");

if(window.navigator.onLine){
internetAvailableSendAllEvents(unsentEventFileLocation, eventParams).done(function() {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

simply call it sendAllEvents

result.resolve();
});
}else {
internetUnavailableSaveEventsToDisk(unsentEventFileLocation, eventParams).done(function() {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Simply call it saveEventToDisk.

sendAnalyticsDataToServer(unsentEventFileLocation, analyticsData, eventParams).done(function () {
result.resolve();
}).fail(function (err) {
console.error("Unable to send file to server");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

in this scenario file is not being sent. please correct the log. also, result.reject() should be added.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

result.reject() ?

unsentEventFileLocation.exists(function (err, exists) {
if (err) {
// logging the error but will still send the current eventParams which needs to be logged
console.error("Error while checking if the error log file exits or not");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: exists.

sendAnalyticsDataToServer(unsentEventFileLocation, analyticsData, eventParams).done(function () {
result.resolve();
}).fail(function (err) {
console.error("Unable to send file to server");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

if the data is not uploaded to the server it should saved back on the disk.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

result.reject() ?

sendAnalyticsDataToServer(unsentEventFileLocation, analyticsData, eventParams).done(function () {
result.resolve();
}).fail(function (err) {
console.error("Unable to send file to server");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

in this case file is not being sent to the server.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

result.reject() ?

console.error("Unable to send file to server");
});
}).fail(function (err) {
// If reading the file fails try to send currentEventParams to server
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

add a log here that file read failed.

sendAnalyticsDataToServer(unsentEventFileLocation, analyticsData, eventParams).done(function () {
result.resolve();
}).fail(function (err) {
console.error("Unable to send file to server");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

file is not being sent to the server here. please correct the log.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

result.reject() ?

}).fail(function (jqXHR, status, errorThrown) {
// incase request to send data to server fails write the events back to disk
analyticsData.forEach(function(event) {
internetUnavailableSaveEventsToDisk(unsentEventFileLocation, eventParams).done(function() {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

simply call the method saveEventsToDisk

@vickramdhawal
Copy link
Copy Markdown
Collaborator

there are linter errors. please fix those as well.

@SnchitGrover SnchitGrover changed the title <WIP Do not Merge>Handling events not sent to Adobe Analytics because of internet unavailability Handling events not sent to Adobe Analytics because of internet unavailability May 2, 2018
@SnchitGrover
Copy link
Copy Markdown
Contributor Author

@vickramdhawal @swmitra

…handler

Snchit adobe analytics local handler
@SnchitGrover SnchitGrover reopened this Mar 19, 2019
@SnchitGrover
Copy link
Copy Markdown
Contributor Author

Hi @adobe/open-source-office. I am an Adobe active employee. Please take care of the CLA check.

@shubhsnov
Copy link
Copy Markdown
Collaborator

@SnchitGrover You can see this to get rid of the CLA check #14606 (comment)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants