Skip to content

Commit

Permalink
Merge pull request #522 from hopetambala/add-timing-logs
Browse files Browse the repository at this point in the history
Adds easytimer dependency and logs timing of checkOnlineStatus
  • Loading branch information
hopetambala authored Jun 26, 2023
2 parents 0b86016 + e312aff commit f684aa6
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 5 deletions.
2 changes: 1 addition & 1 deletion App.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import React from "react";
import { Provider as PaperProvider } from "react-native-paper";

import { initialize } from "./services/parse/auth";
import getAWSLogger from "@modules/aws-logging/hook";
import getAWSLogger from "@modules/aws-logging/logger";

initialize();

Expand Down
File renamed without changes.
30 changes: 27 additions & 3 deletions modules/offline/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
import NetInfo from "@react-native-community/netinfo";
import * as Network from "expo-network";
import { Platform } from "react-native";
import Timer from "easytimer";
import getAWSLogger from "@modules/aws-logging/logger";

// checks whether user is connected to internet, return true if connected, false otherwise
const checkOnlineStatus = () =>
new Promise((resolve, reject) => {
const checkOnlineStatus = () => {
let timer = new Timer();
timer.start({precision: 'seconds'});
return new Promise((resolve, reject) => {
if (Platform.OS === "ios") {
Network.getNetworkStateAsync().then(
(status) => {
timer.stop();
getAWSLogger().log({
type: "CHECK_ONLINE_STATUS_SUCCESS_TIMER_SUCCESS",
seconds: timer.getTimeValues().toString(),
});
resolve(status.isConnected);
},
(error) => {
timer.stop();
getAWSLogger().log({
type: "CHECK_ONLINE_STATUS_SUCCESS_TIMER_ERROR",
seconds: timer.getTimeValues().toString(),
});
reject(error);
}
);
Expand All @@ -23,8 +37,18 @@ const checkOnlineStatus = () =>
state.details.strength !== undefined &&
state.details.strength > 10
) {
timer.stop();
getAWSLogger().log({
type: "CHECK_ONLINE_STATUS_SUCCESS_TIMER_SUCCESS",
seconds: timer.getTimeValues().toString(),
});
resolve(true);
} else {
timer.stop();
getAWSLogger().log({
type: "CHECK_ONLINE_STATUS_SUCCESS_TIMER_ERROR",
seconds: timer.getTimeValues().toString(),
});
resolve(false);
}
},
Expand All @@ -34,5 +58,5 @@ const checkOnlineStatus = () =>
);
}
});

}
export default checkOnlineStatus;
2 changes: 1 addition & 1 deletion modules/offline/post/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { isEmpty } from "@modules/utils";
import { Platform } from "react-native";

import checkOnlineStatus from "..";
import getAWSLogger from "@modules/aws-logging/hook";
import getAWSLogger from "@modules/aws-logging/logger";

const cleanupPostedOfflineForms = async () => {
await deleteData("offlineIDForms");
Expand Down
12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"@react-navigation/stack": "5.14.5",
"axios": "0.21.1",
"deprecated-react-native-prop-types": "^2.3.0",
"easytimer": "^1.1.3",
"expo": "^46.0.0",
"expo-application": "~4.2.2",
"expo-asset": "~8.6.1",
Expand Down

0 comments on commit f684aa6

Please sign in to comment.