Add schedule logs feature and enhance schedule management

- Introduced a new component `ShowSchedulesLogs` to display logs for each schedule, allowing users to view deployment logs associated with their schedules.
- Updated the `ShowSchedules` component to integrate the new logs feature, providing a button to access logs for each schedule.
- Enhanced the `schedule` schema by adding an `appName` column to better identify applications associated with schedules.
- Updated the API to support fetching deployments with their associated schedules, improving data retrieval for the frontend.
- Implemented utility functions for managing schedule-related operations, including creating and removing deployments linked to schedules.
This commit is contained in:
Mauricio Siu
2025-05-02 04:29:32 -06:00
parent 442f051457
commit f2bb01c800
14 changed files with 5949 additions and 71 deletions

View File

@@ -4,8 +4,10 @@ import {
createScheduleSchema,
schedules,
} from "@dokploy/server/db/schema/schedule";
import { eq } from "drizzle-orm";
import { desc, eq } from "drizzle-orm";
import { createTRPCRouter, protectedProcedure } from "../trpc";
import { runCommand } from "@dokploy/server/index";
import { deployments } from "@dokploy/server/db/schema/deployment";
export const scheduleRouter = createTRPCRouter({
create: protectedProcedure
@@ -59,10 +61,15 @@ export const scheduleRouter = createTRPCRouter({
list: protectedProcedure
.input(z.object({ applicationId: z.string() }))
.query(async ({ ctx, input }) => {
return ctx.db
.select()
.from(schedules)
.where(eq(schedules.applicationId, input.applicationId));
return ctx.db.query.schedules.findMany({
where: eq(schedules.applicationId, input.applicationId),
with: {
application: true,
deployments: {
orderBy: [desc(deployments.createdAt)],
},
},
});
}),
one: protectedProcedure
@@ -84,20 +91,10 @@ export const scheduleRouter = createTRPCRouter({
}),
runManually: protectedProcedure
.input(z.object({ scheduleId: z.string() }))
.mutation(async ({ ctx, input }) => {
const schedule = await ctx.db
.select()
.from(schedules)
.where(eq(schedules.scheduleId, input.scheduleId));
.input(z.object({ scheduleId: z.string().min(1) }))
.mutation(async ({ input }) => {
await runCommand(input.scheduleId);
if (!schedule) {
throw new TRPCError({
code: "NOT_FOUND",
message: "Schedule not found",
});
}
return schedule;
return true;
}),
});