Files
dokploy/packages/server/src/utils/schedules/index.ts
Mauricio Siu 3072795232 Enhance schedule initialization and management features
- Introduced a new `initSchedules` function to initialize and schedule active schedules from the database, improving the management of scheduled tasks.
- Updated the `createSchedule` and `updateSchedule` functions to handle scheduling jobs based on the enabled status of schedules, ensuring proper job management.
- Refactored the `removeScheduleJob` utility to cancel existing scheduled jobs, enhancing the flexibility of schedule updates.
- Improved the `HandleSchedules` and `ShowSchedules` components by removing unused imports and enhancing the user interface for better clarity and usability.
2025-05-02 23:05:39 -06:00

29 lines
737 B
TypeScript

import { db } from "../../db/index";
import { schedules } from "@dokploy/server/db/schema";
import { eq } from "drizzle-orm";
import { scheduleJob } from "./utils";
export const initSchedules = async () => {
try {
const schedulesResult = await db.query.schedules.findMany({
where: eq(schedules.enabled, true),
with: {
server: true,
application: true,
compose: true,
user: true,
},
});
console.log(`Initializing ${schedulesResult.length} schedules`);
for (const schedule of schedulesResult) {
scheduleJob(schedule);
console.log(
`Initialized schedule: ${schedule.name} ${schedule.scheduleType}`,
);
}
} catch (error) {
console.log(`Error initializing schedules: ${error}`);
}
};