REACT_APP_MACHINE_PING_INTERVAL
parent
b1e0b4520f
commit
f66a005b88
|
@ -7,6 +7,7 @@ import { useToast } from "../../../hooks";
|
||||||
import * as api from "../api";
|
import * as api from "../api";
|
||||||
|
|
||||||
const initialState = { on: false };
|
const initialState = { on: false };
|
||||||
|
const defaultPingInterval = 1200000; //20 minutes
|
||||||
|
|
||||||
const WakeComponent = ({ machine, addLog }) => {
|
const WakeComponent = ({ machine, addLog }) => {
|
||||||
const [state, setState] = useState(initialState);
|
const [state, setState] = useState(initialState);
|
||||||
|
@ -14,6 +15,9 @@ const WakeComponent = ({ machine, addLog }) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { success, error } = useToast();
|
const { success, error } = useToast();
|
||||||
|
|
||||||
|
const pingInterval =
|
||||||
|
process.env.REACT_APP_MACHINE_PING_INTERVAL || defaultPingInterval;
|
||||||
|
|
||||||
const getCurrentDateTime = useCallback(() => {
|
const getCurrentDateTime = useCallback(() => {
|
||||||
const currentDateTime = Date.now();
|
const currentDateTime = Date.now();
|
||||||
const result = t("DATE_FORMAT", {
|
const result = t("DATE_FORMAT", {
|
||||||
|
@ -24,6 +28,7 @@ const WakeComponent = ({ machine, addLog }) => {
|
||||||
|
|
||||||
const wakeMachine = useCallback(async () => {
|
const wakeMachine = useCallback(async () => {
|
||||||
const result = await api.wakeMachine(machine.macAddress);
|
const result = await api.wakeMachine(machine.macAddress);
|
||||||
|
setState(prev => ({ ...prev, on: result.success }));
|
||||||
addLog(
|
addLog(
|
||||||
`[${getCurrentDateTime()}] [Wake]: Success: ${result.success}. Status: ${
|
`[${getCurrentDateTime()}] [Wake]: Success: ${result.success}. Status: ${
|
||||||
result.status
|
result.status
|
||||||
|
@ -47,8 +52,8 @@ const WakeComponent = ({ machine, addLog }) => {
|
||||||
});
|
});
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
setTrigger(prev => !prev);
|
setTrigger(prev => !prev);
|
||||||
}, 60000);
|
}, pingInterval);
|
||||||
}, [machine, addLog, getCurrentDateTime, trigger]);
|
}, [machine, addLog, getCurrentDateTime, pingInterval, trigger]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Tooltip title={t("Machine.Actions.Wake")}>
|
<Tooltip title={t("Machine.Actions.Wake")}>
|
||||||
|
|
Loading…
Reference in New Issue