hassio-nextcloud-backup/nextcloud_backup/rootfs/opt/nextcloud_backup/tools/status.js

39 lines
866 B
JavaScript
Raw Normal View History

import * as hassioApiTools from "./hassioApiTools.js";
import logger from "../config/winston.js"
2019-12-19 15:08:47 +01:00
let status = {
2019-12-19 15:08:47 +01:00
status: "idle",
last_backup: null,
2020-11-09 12:42:26 +01:00
next_backup: null,
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 = null;
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) {
let old_state_str = JSON.stringify(status);
if(old_state_str !== JSON.stringify(new_state)){
status = new_state;
hassioApiTools.publish_state(status);
}
2019-12-19 15:08:47 +01:00
}
export function setError(message, error_code){
// 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);
}