mirror of
https://github.com/nicotsx/ironmount.git
synced 2025-12-10 12:10:51 +01:00
refactor: unify backend and frontend servers (#3)
* refactor: unify backend and frontend servers * refactor: correct paths for openapi & drizzle * refactor: move api-client to client * fix: drizzle paths * chore: fix linting issues * fix: form reset issue
This commit is contained in:
44
app/server/core/scheduler.ts
Normal file
44
app/server/core/scheduler.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import cron, { type ScheduledTask } from "node-cron";
|
||||
import { logger } from "../utils/logger";
|
||||
|
||||
export abstract class Job {
|
||||
abstract run(): Promise<unknown>;
|
||||
}
|
||||
|
||||
type JobConstructor = new () => Job;
|
||||
|
||||
class SchedulerClass {
|
||||
private tasks: ScheduledTask[] = [];
|
||||
|
||||
async start() {
|
||||
logger.info("Scheduler started");
|
||||
}
|
||||
|
||||
build(JobClass: JobConstructor) {
|
||||
const job = new JobClass();
|
||||
return {
|
||||
schedule: (cronExpression: string) => {
|
||||
const task = cron.schedule(cronExpression, async () => {
|
||||
try {
|
||||
await job.run();
|
||||
} catch (error) {
|
||||
logger.error(`Job ${JobClass.name} failed:`, error);
|
||||
}
|
||||
});
|
||||
|
||||
this.tasks.push(task);
|
||||
logger.info(`Scheduled job ${JobClass.name} with cron: ${cronExpression}`);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
async stop() {
|
||||
for (const task of this.tasks) {
|
||||
task.stop();
|
||||
}
|
||||
this.tasks = [];
|
||||
logger.info("Scheduler stopped");
|
||||
}
|
||||
}
|
||||
|
||||
export const Scheduler = new SchedulerClass();
|
||||
Reference in New Issue
Block a user