From f66a005b88b6f5c1f90b361c9638dbc6384e8acd Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Sun, 18 Apr 2021 01:52:27 +0300 Subject: [PATCH] REACT_APP_MACHINE_PING_INTERVAL --- src/features/machines/components/WakeComponent.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/features/machines/components/WakeComponent.js b/src/features/machines/components/WakeComponent.js index 4336f04..749b76e 100644 --- a/src/features/machines/components/WakeComponent.js +++ b/src/features/machines/components/WakeComponent.js @@ -7,6 +7,7 @@ import { useToast } from "../../../hooks"; import * as api from "../api"; const initialState = { on: false }; +const defaultPingInterval = 1200000; //20 minutes const WakeComponent = ({ machine, addLog }) => { const [state, setState] = useState(initialState); @@ -14,6 +15,9 @@ const WakeComponent = ({ machine, addLog }) => { const { t } = useTranslation(); const { success, error } = useToast(); + const pingInterval = + process.env.REACT_APP_MACHINE_PING_INTERVAL || defaultPingInterval; + const getCurrentDateTime = useCallback(() => { const currentDateTime = Date.now(); const result = t("DATE_FORMAT", { @@ -24,6 +28,7 @@ const WakeComponent = ({ machine, addLog }) => { const wakeMachine = useCallback(async () => { const result = await api.wakeMachine(machine.macAddress); + setState(prev => ({ ...prev, on: result.success })); addLog( `[${getCurrentDateTime()}] [Wake]: Success: ${result.success}. Status: ${ result.status @@ -47,8 +52,8 @@ const WakeComponent = ({ machine, addLog }) => { }); setTimeout(() => { setTrigger(prev => !prev); - }, 60000); - }, [machine, addLog, getCurrentDateTime, trigger]); + }, pingInterval); + }, [machine, addLog, getCurrentDateTime, pingInterval, trigger]); return (