REACT_APP_MACHINE_PING_INTERVAL

master
Tudor Stanciu 2021-04-18 01:52:27 +03:00
parent b1e0b4520f
commit f66a005b88
1 changed files with 7 additions and 2 deletions

View File

@ -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 (
<Tooltip title={t("Machine.Actions.Wake")}>