mirror of
https://github.com/gnmyt/myspeed.git
synced 2026-02-10 23:58:38 -06:00
40 lines
934 B
JavaScript
40 lines
934 B
JavaScript
import schedule from 'node-schedule';
|
|
import { triggerEvent } from "../controller/integrations.js";
|
|
|
|
let currentState = "ping";
|
|
let job;
|
|
|
|
export const setState = (state = "ping") => {
|
|
currentState = state;
|
|
};
|
|
|
|
export const sendPing = async (type, message) => {
|
|
await triggerEvent("minutePassed", {type, message});
|
|
};
|
|
|
|
export const sendCurrent = async () => {
|
|
if (currentState === "ping") await sendPing();
|
|
};
|
|
|
|
export const sendError = async (error = "Unknown error") => {
|
|
await triggerEvent("testFailed", error);
|
|
};
|
|
|
|
export const sendRunning = async () => {
|
|
await triggerEvent("testStarted");
|
|
};
|
|
|
|
export const sendFinished = async (data) => {
|
|
await triggerEvent("testFinished", data);
|
|
};
|
|
|
|
export const startTimer = () => {
|
|
job = schedule.scheduleJob('* * * * *', () => sendCurrent());
|
|
};
|
|
|
|
export const stopTimer = () => {
|
|
if (job !== undefined) {
|
|
job.cancel();
|
|
job = undefined;
|
|
}
|
|
}; |