Skip to content

Commit

Permalink
call ping on mount
Browse files Browse the repository at this point in the history
  • Loading branch information
pankona committed Jan 28, 2022
1 parent fc85fbd commit 14e0bb8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
13 changes: 13 additions & 0 deletions hashira-web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,19 @@ const App: React.VFC = () => {
[user]
);

const intervalMs = 1000 * 60 * 3; // 3 minutes

React.useEffect(() => {
firebase.ping();
const intervalId = setInterval(() => {
firebase.ping();
}, intervalMs);

return () => {
clearInterval(intervalId);
};
}, []);

React.useEffect(() => {
if (user) {
Promise.all([
Expand Down
14 changes: 14 additions & 0 deletions hashira-web/src/firebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,20 @@ export const updateTasks2 = async (tasksObject: TasksObject) => {
}
};

export const ping = async () => {
try {
await functions.httpsCallable(
functions.getFunctions(undefined, "asia-northeast1"),
"call?method=ping"
)();
} catch (e) {
// FIXME:
// currently cloud functions doesn't return appropriate response
// that fits httpsCallable protocol even if the function succeeded.
console.log("error:", e);
}
};

export const fetchTaskAndPriorities = async (uid: string) => {
const db = getFirestore();
const docRef = doc(db, "tasksAndPriorities", uid);
Expand Down

0 comments on commit 14e0bb8

Please sign in to comment.