Kopia next run / last run
This commit is contained in:
parent
fe236e18c0
commit
faae29d5f4
@ -500,6 +500,7 @@
|
||||
"status": "Status",
|
||||
"size": "Size",
|
||||
"lastrun": "Last Run",
|
||||
"nextrun": "Next Run"
|
||||
"nextrun": "Next Run",
|
||||
"failed": "Failed"
|
||||
}
|
||||
}
|
||||
@ -4,18 +4,46 @@ import Container from "components/services/widget/container";
|
||||
import Block from "components/services/widget/block";
|
||||
import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||
|
||||
function relativeDate(date) {
|
||||
const seconds = Math.abs(Math.floor((new Date() - date) / 1000));
|
||||
|
||||
let interval = Math.abs(seconds / 31536000);
|
||||
|
||||
if (interval > 1) {
|
||||
return `${Math.floor(interval)} y`;
|
||||
}
|
||||
interval = seconds / 2592000;
|
||||
if (interval > 1) {
|
||||
return `${Math.floor(interval)} mo`;
|
||||
}
|
||||
interval = seconds / 86400;
|
||||
if (interval > 1) {
|
||||
return `${Math.floor(interval)} d`;
|
||||
}
|
||||
interval = seconds / 3600;
|
||||
if (interval > 1) {
|
||||
return `${Math.floor(interval)} h`;
|
||||
}
|
||||
interval = seconds / 60;
|
||||
if (interval > 1) {
|
||||
return `${Math.floor(interval)} m`;
|
||||
}
|
||||
return `${Math.floor(seconds)} s`;
|
||||
}
|
||||
|
||||
export default function Component({ service }) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const { widget } = service;
|
||||
const { data: statusData, error: statusError } = useWidgetAPI(widget, "status");
|
||||
const { data: tasksData, error: tasksError } = useWidgetAPI(widget, "tasks");
|
||||
|
||||
if (statusError || tasksError) {
|
||||
return <Container error={statusError ?? tasksError} />;
|
||||
if (statusError) {
|
||||
return <Container error={statusError} />;
|
||||
}
|
||||
|
||||
if (!statusData || !tasksData) {
|
||||
const source = statusData?.sources[0];
|
||||
|
||||
if (!statusData || !source) {
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="kopia.status" />
|
||||
@ -26,32 +54,15 @@ export default function Component({ service }) {
|
||||
);
|
||||
}
|
||||
|
||||
function fromTasks(task) {
|
||||
for (let i=0; i<task.length; i += 1) {
|
||||
const taskKind = task[i].kind;
|
||||
if ( taskKind === "Snapshot") {
|
||||
const taskStatus = task[i].status;
|
||||
return taskStatus;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
const nowTime = new Date();
|
||||
const nextTime = new Date(statusData.sources[0].nextSnapshotTime);
|
||||
const leftTime = new Date(nextTime - nowTime);
|
||||
const hours = leftTime.getUTCHours().toString().padStart(2, '0');
|
||||
const minutes = leftTime.getUTCMinutes().toString().padStart(2, '0');
|
||||
const h = "h ";
|
||||
const m = "m";
|
||||
const time = (hours + h + minutes + m);
|
||||
const lastRun = source.lastSnapshot.stats.errorCount === 0 ? new Date(source.lastSnapshot.startTime) : t("kopia.failed");
|
||||
const nextTime = source.nextSnapshotTime ? new Date(source.nextSnapshotTime) : null;
|
||||
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="kopia.status" value={ statusData.sources[0].status } />
|
||||
<Block label="kopia.size" value={t("common.bbytes", { value: statusData.sources[0].lastSnapshot.stats.totalSize, maximumFractionDigits: 1 })} />
|
||||
<Block label="kopia.lastrun" value={ fromTasks(tasksData.tasks) } />
|
||||
<Block label="kopia.nextrun" value={ time } />
|
||||
<Block label="kopia.status" value={ source.status } />
|
||||
<Block label="kopia.size" value={t("common.bbytes", { value: source.lastSnapshot.stats.totalSize, maximumFractionDigits: 1 })} />
|
||||
<Block label="kopia.lastrun" value={ relativeDate(lastRun) } />
|
||||
{nextTime && <Block label="kopia.nextrun" value={ relativeDate(nextTime) } />}
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
@ -8,9 +8,6 @@ const widget = {
|
||||
status: {
|
||||
endpoint: "api/v1/sources",
|
||||
},
|
||||
tasks: {
|
||||
endpoint: "api/v1/tasks",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user