Admin: Add message with failed / total nodes for nodes.json-task.
This commit is contained in:
parent
fb87695b3e
commit
b6a67d6e74
12 changed files with 120 additions and 20 deletions
|
@ -1,8 +1,12 @@
|
|||
import {fixNodeFilenames} from "../services/nodeService";
|
||||
import {jobResultOkay} from "./scheduler";
|
||||
|
||||
export default {
|
||||
name: 'FixNodeFilenamesJob',
|
||||
description: 'Makes sure node files (holding fastd key, name, etc.) are correctly named.',
|
||||
|
||||
run: fixNodeFilenames
|
||||
async run() {
|
||||
await fixNodeFilenames();
|
||||
return jobResultOkay();
|
||||
},
|
||||
}
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
import * as MailService from "../services/mailService"
|
||||
import {jobResultOkay} from "./scheduler";
|
||||
|
||||
export default {
|
||||
name: 'MailQueueJob',
|
||||
description: 'Send pending emails (up to 5 attempts in case of failures).',
|
||||
|
||||
run: MailService.sendPendingMails,
|
||||
}
|
||||
async run() {
|
||||
await MailService.sendPendingMails();
|
||||
return jobResultOkay();
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
import * as MonitoringService from "../services/monitoringService";
|
||||
import {jobResultOkay} from "./scheduler";
|
||||
|
||||
export default {
|
||||
name: 'MonitoringMailsSendingJob',
|
||||
description: 'Sends monitoring emails depending on the monitoring state of nodes retrieved by the NodeInformationRetrievalJob.',
|
||||
|
||||
run: MonitoringService.sendMonitoringMails,
|
||||
async run() {
|
||||
await MonitoringService.sendMonitoringMails();
|
||||
return jobResultOkay();
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,8 +1,20 @@
|
|||
import * as MonitoringService from "../services/monitoringService";
|
||||
import {jobResultOkay, jobResultWarning} from "./scheduler";
|
||||
|
||||
export default {
|
||||
name: 'NodeInformationRetrievalJob',
|
||||
description: 'Fetches the nodes.json and calculates and stores the monitoring / online status for registered nodes.',
|
||||
|
||||
run: MonitoringService.retrieveNodeInformation,
|
||||
async run () {
|
||||
const result = await MonitoringService.retrieveNodeInformation();
|
||||
if (result.failedParsingNodesCount > 0) {
|
||||
return jobResultWarning(
|
||||
`Warning: ${result.failedParsingNodesCount} of ${result.totalNodesCount} nodes could not be processed.`
|
||||
);
|
||||
} else {
|
||||
return jobResultOkay(
|
||||
`${result.totalNodesCount} nodes have been processed.`
|
||||
);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
import * as MonitoringService from "../services/monitoringService";
|
||||
import {jobResultOkay} from "./scheduler";
|
||||
|
||||
export default {
|
||||
name: 'OfflineNodesDeletionJob',
|
||||
description: 'Delete nodes that are offline for more than 100 days.',
|
||||
|
||||
run: MonitoringService.deleteOfflineNodes,
|
||||
async run() {
|
||||
await MonitoringService.deleteOfflineNodes();
|
||||
return jobResultOkay();
|
||||
},
|
||||
};
|
||||
|
|
|
@ -10,11 +10,35 @@ import NodeInformationRetrievalJob from "./NodeInformationRetrievalJob";
|
|||
import MonitoringMailsSendingJob from "./MonitoringMailsSendingJob";
|
||||
import OfflineNodesDeletionJob from "./OfflineNodesDeletionJob";
|
||||
|
||||
export enum JobResultState {
|
||||
OKAY = "okay",
|
||||
WARNING = "warning",
|
||||
}
|
||||
|
||||
export type JobResult = {
|
||||
state: JobResultState,
|
||||
message?: string,
|
||||
};
|
||||
|
||||
export function jobResultOkay(message?: string): JobResult {
|
||||
return {
|
||||
state: JobResultState.OKAY,
|
||||
message
|
||||
}
|
||||
}
|
||||
|
||||
export function jobResultWarning(message?: string): JobResult {
|
||||
return {
|
||||
state: JobResultState.WARNING,
|
||||
message
|
||||
}
|
||||
}
|
||||
|
||||
export interface Job {
|
||||
name: string,
|
||||
description: string,
|
||||
|
||||
run(): Promise<void>,
|
||||
run(): Promise<JobResult>,
|
||||
}
|
||||
|
||||
export enum TaskState {
|
||||
|
@ -34,6 +58,7 @@ export class Task {
|
|||
public lastRunStarted: moment.Moment | null,
|
||||
public lastRunDuration: number | null,
|
||||
public state: TaskState,
|
||||
public result: JobResult | null,
|
||||
public enabled: boolean,
|
||||
) {}
|
||||
|
||||
|
@ -47,7 +72,7 @@ export class Task {
|
|||
this.lastRunStarted = this.runningSince;
|
||||
this.state = TaskState.RUNNING;
|
||||
|
||||
const done = (state: TaskState):void => {
|
||||
const done = (state: TaskState, result: JobResult | null): void => {
|
||||
const now = moment();
|
||||
const duration = now.diff(this.runningSince || now);
|
||||
Logger.tag('jobs').profile('[%sms]\t%s', duration, this.name);
|
||||
|
@ -55,13 +80,14 @@ export class Task {
|
|||
this.runningSince = null;
|
||||
this.lastRunDuration = duration;
|
||||
this.state = state;
|
||||
this.result = result;
|
||||
};
|
||||
|
||||
this.job.run().then(() => {
|
||||
done(TaskState.IDLE);
|
||||
this.job.run().then(result => {
|
||||
done(TaskState.IDLE, result);
|
||||
}).catch((err: any) => {
|
||||
Logger.tag('jobs').error("Job %s failed: %s", this.name, err);
|
||||
done(TaskState.FAILED);
|
||||
done(TaskState.FAILED, null);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -92,7 +118,8 @@ function schedule(expr: string, job: Job): void {
|
|||
null,
|
||||
null,
|
||||
TaskState.IDLE,
|
||||
true
|
||||
null,
|
||||
true,
|
||||
);
|
||||
|
||||
cron.schedule(expr, task.run);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue