ESLint: Auto reformat and fixing some warnings / errors.
This commit is contained in:
parent
5237db38e0
commit
91690509d3
50 changed files with 2141 additions and 1493 deletions
|
@ -1,12 +1,13 @@
|
|||
import {fixNodeFilenames} from "../services/nodeService";
|
||||
import {jobResultOkay} from "./scheduler";
|
||||
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.',
|
||||
name: "FixNodeFilenamesJob",
|
||||
description:
|
||||
"Makes sure node files (holding fastd key, name, etc.) are correctly named.",
|
||||
|
||||
async run() {
|
||||
await fixNodeFilenames();
|
||||
return jobResultOkay();
|
||||
},
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import * as MailService from "../services/mailService"
|
||||
import {jobResultOkay} from "./scheduler";
|
||||
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).',
|
||||
name: "MailQueueJob",
|
||||
description: "Send pending emails (up to 5 attempts in case of failures).",
|
||||
|
||||
async run() {
|
||||
await MailService.sendPendingMails();
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
import * as MonitoringService from "../services/monitoringService";
|
||||
import {jobResultOkay} from "./scheduler";
|
||||
import { jobResultOkay } from "./scheduler";
|
||||
|
||||
export default {
|
||||
name: 'MonitoringMailsSendingJob',
|
||||
description: 'Sends monitoring emails depending on the monitoring state of nodes retrieved by the NodeInformationRetrievalJob.',
|
||||
name: "MonitoringMailsSendingJob",
|
||||
description:
|
||||
"Sends monitoring emails depending on the monitoring state of nodes retrieved by the NodeInformationRetrievalJob.",
|
||||
|
||||
async run() {
|
||||
await MonitoringService.sendMonitoringMails();
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
import * as MonitoringService from "../services/monitoringService";
|
||||
import {jobResultOkay, jobResultWarning} from "./scheduler";
|
||||
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.',
|
||||
name: "NodeInformationRetrievalJob",
|
||||
description:
|
||||
"Fetches the nodes.json and calculates and stores the monitoring / online status for registered nodes.",
|
||||
|
||||
async run () {
|
||||
async run() {
|
||||
const result = await MonitoringService.retrieveNodeInformation();
|
||||
if (result.failedParsingNodesCount > 0) {
|
||||
return jobResultWarning(
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import * as MonitoringService from "../services/monitoringService";
|
||||
import {jobResultOkay} from "./scheduler";
|
||||
import { jobResultOkay } from "./scheduler";
|
||||
|
||||
export default {
|
||||
name: 'OfflineNodesDeletionJob',
|
||||
description: 'Delete nodes that are offline for more than 100 days.',
|
||||
name: "OfflineNodesDeletionJob",
|
||||
description: "Delete nodes that are offline for more than 100 days.",
|
||||
|
||||
async run() {
|
||||
await MonitoringService.deleteOfflineNodes();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import cron from "node-cron";
|
||||
import moment from "moment";
|
||||
|
||||
import {config} from "../config";
|
||||
import { config } from "../config";
|
||||
import Logger from "../logger";
|
||||
|
||||
import MailQueueJob from "./MailQueueJob";
|
||||
|
@ -16,29 +16,29 @@ export enum JobResultState {
|
|||
}
|
||||
|
||||
export type JobResult = {
|
||||
state: JobResultState,
|
||||
message?: string,
|
||||
state: JobResultState;
|
||||
message?: string;
|
||||
};
|
||||
|
||||
export function jobResultOkay(message?: string): JobResult {
|
||||
return {
|
||||
state: JobResultState.OKAY,
|
||||
message
|
||||
}
|
||||
message,
|
||||
};
|
||||
}
|
||||
|
||||
export function jobResultWarning(message?: string): JobResult {
|
||||
return {
|
||||
state: JobResultState.WARNING,
|
||||
message
|
||||
}
|
||||
message,
|
||||
};
|
||||
}
|
||||
|
||||
export interface Job {
|
||||
name: string,
|
||||
description: string,
|
||||
name: string;
|
||||
description: string;
|
||||
|
||||
run(): Promise<JobResult>,
|
||||
run(): Promise<JobResult>;
|
||||
}
|
||||
|
||||
export enum TaskState {
|
||||
|
@ -59,7 +59,7 @@ export class Task {
|
|||
public lastRunDuration: number | null,
|
||||
public state: TaskState,
|
||||
public result: JobResult | null,
|
||||
public enabled: boolean,
|
||||
public enabled: boolean
|
||||
) {}
|
||||
|
||||
run(): void {
|
||||
|
@ -75,7 +75,7 @@ export class Task {
|
|||
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);
|
||||
Logger.tag("jobs").profile("[%sms]\t%s", duration, this.name);
|
||||
|
||||
this.runningSince = null;
|
||||
this.lastRunDuration = duration;
|
||||
|
@ -83,16 +83,19 @@ export class Task {
|
|||
this.result = result;
|
||||
};
|
||||
|
||||
this.job.run().then(result => {
|
||||
done(TaskState.IDLE, result);
|
||||
}).catch(err => {
|
||||
Logger.tag('jobs').error("Job %s failed: %s", this.name, err);
|
||||
done(TaskState.FAILED, null);
|
||||
});
|
||||
this.job
|
||||
.run()
|
||||
.then((result) => {
|
||||
done(TaskState.IDLE, result);
|
||||
})
|
||||
.catch((err) => {
|
||||
Logger.tag("jobs").error("Job %s failed: %s", this.name, err);
|
||||
done(TaskState.FAILED, null);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
type Tasks = {[key: string]: Task};
|
||||
type Tasks = { [key: string]: Task };
|
||||
|
||||
const tasks: Tasks = {};
|
||||
|
||||
|
@ -104,7 +107,7 @@ function nextTaskId(): number {
|
|||
}
|
||||
|
||||
function schedule(expr: string, job: Job): void {
|
||||
Logger.tag('jobs').info('Scheduling job: %s %s', expr, job.name);
|
||||
Logger.tag("jobs").info("Scheduling job: %s %s", expr, job.name);
|
||||
|
||||
const id = nextTaskId();
|
||||
|
||||
|
@ -119,33 +122,35 @@ function schedule(expr: string, job: Job): void {
|
|||
null,
|
||||
TaskState.IDLE,
|
||||
null,
|
||||
true,
|
||||
true
|
||||
);
|
||||
|
||||
cron.schedule(expr, () => task.run());
|
||||
|
||||
tasks['' + id] = task;
|
||||
tasks["" + id] = task;
|
||||
}
|
||||
|
||||
export function init() {
|
||||
Logger.tag('jobs').info('Scheduling background jobs...');
|
||||
Logger.tag("jobs").info("Scheduling background jobs...");
|
||||
|
||||
try {
|
||||
schedule('0 */1 * * * *', MailQueueJob);
|
||||
schedule('15 */1 * * * *', FixNodeFilenamesJob);
|
||||
schedule("0 */1 * * * *", MailQueueJob);
|
||||
schedule("15 */1 * * * *", FixNodeFilenamesJob);
|
||||
|
||||
if (config.client.monitoring.enabled) {
|
||||
schedule('30 */15 * * * *', NodeInformationRetrievalJob);
|
||||
schedule('45 */5 * * * *', MonitoringMailsSendingJob);
|
||||
schedule('0 0 3 * * *', OfflineNodesDeletionJob); // every night at 3:00
|
||||
schedule("30 */15 * * * *", NodeInformationRetrievalJob);
|
||||
schedule("45 */5 * * * *", MonitoringMailsSendingJob);
|
||||
schedule("0 0 3 * * *", OfflineNodesDeletionJob); // every night at 3:00
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
Logger.tag('jobs').error('Error during scheduling of background jobs:', error);
|
||||
} catch (error) {
|
||||
Logger.tag("jobs").error(
|
||||
"Error during scheduling of background jobs:",
|
||||
error
|
||||
);
|
||||
throw error;
|
||||
}
|
||||
|
||||
Logger.tag('jobs').info('Scheduling of background jobs done.');
|
||||
Logger.tag("jobs").info("Scheduling of background jobs done.");
|
||||
}
|
||||
|
||||
export function getTasks(): Tasks {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue