hassio-nextcloud-backup/nextcloud_backup/backend/src/tools/status.ts

41 lines
1011 B
TypeScript
Raw Normal View History

2022-09-27 23:38:40 +02:00
import { publish_state } from "../services/homeAssistantService.js";
import logger from "../config/winston.js"
import { type Status } from "../types/status.js";
2019-12-19 15:08:47 +01:00
let status: Status = {
2019-12-19 15:08:47 +01:00
status: "idle",
last_backup: undefined,
next_backup: undefined,
progress: -1,
2020-02-15 14:28:48 +01:00
};
2019-12-19 15:08:47 +01:00
export function init() {
if (status.status !== "idle") {
status.status = "idle";
status.message = undefined;
status.progress = -1;
2019-12-19 15:08:47 +01:00
}
}
export function getStatus() {
return status;
2019-12-19 15:08:47 +01:00
}
export function setStatus(new_state: Status) {
const old_state_str = JSON.stringify(status);
if(old_state_str !== JSON.stringify(new_state)){
status = new_state;
2022-09-27 23:38:40 +02:00
publish_state(status);
}
2019-12-19 15:08:47 +01:00
}
export function setError(message: string, error_code: number){
// Check if we don't have another error stored
if (status.status != "error") {
status.status = "error"
status.message = message
status.error_code = error_code;
}
logger.error(message);
}