mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-09-30 07:12:36 -05:00
31 lines
590 B
TypeScript
31 lines
590 B
TypeScript
import { logger } from "../utils/logger";
|
|
|
|
export class Routine {
|
|
readonly name;
|
|
private readonly func;
|
|
|
|
constructor({
|
|
name,
|
|
func,
|
|
}: {
|
|
name: string;
|
|
func: () => Promise<void>;
|
|
}) {
|
|
this.name = name;
|
|
this.func = func;
|
|
}
|
|
|
|
async run() {
|
|
logger.info(`Running routine: ${this.name}`);
|
|
const startTime = performance.now();
|
|
try {
|
|
await this.func();
|
|
} catch (error) {
|
|
logger.error(`Error running routine ${this.name}: ${error}`);
|
|
return;
|
|
}
|
|
const endTime = performance.now();
|
|
logger.info(`Routine ${this.name} completed in ${endTime - startTime}ms`);
|
|
}
|
|
}
|