sendou.ink/app/routines/routine.server.ts
Kalle 3a0953f33d
Some checks are pending
E2E Tests / e2e (push) Waiting to run
Tests and checks on push / run-checks-and-tests (push) Waiting to run
Updates translation progress / update-translation-progress-issue (push) Waiting to run
Add Sentry enabled FF
2026-05-16 07:25:00 +03:00

45 lines
935 B
TypeScript

import * as Sentry from "@sentry/react-router";
import { logger } from "../utils/logger";
const SENTRY_ENABLED = import.meta.env.VITE_SENTRY_ENABLED === "true";
export class Routine {
private name;
private func;
constructor({
name,
func,
}: {
name: string;
func: () => Promise<void>;
}) {
this.name = name;
this.func = func;
}
async run() {
logger.info(`Running routine: ${this.name}`);
const work = async () => {
const startTime = performance.now();
try {
await this.func();
} catch (error) {
logger.error(`Error running routine ${this.name}: ${error}`);
if (SENTRY_ENABLED) {
Sentry.captureException(error);
}
return;
}
const endTime = performance.now();
logger.info(`Routine ${this.name} completed in ${endTime - startTime}ms`);
};
if (SENTRY_ENABLED) {
await Sentry.startSpan({ name: this.name, op: "cron" }, work);
} else {
await work();
}
}
}