mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
Refactor ShowSchedules component and enhance error handling in schedule API
- Simplified the mutation calls in the ShowSchedules component by removing success callbacks, streamlining the code. - Improved the display logic to conditionally render the HandleSchedules component when schedules are present. - Enhanced error handling in the runManually mutation within the schedule API, ensuring proper logging and error messaging for better debugging.
This commit is contained in:
@@ -39,18 +39,10 @@ export const ShowSchedules = ({ applicationId }: Props) => {
|
|||||||
const utils = api.useUtils();
|
const utils = api.useUtils();
|
||||||
|
|
||||||
const { mutateAsync: deleteSchedule, isLoading: isDeleting } =
|
const { mutateAsync: deleteSchedule, isLoading: isDeleting } =
|
||||||
api.schedule.delete.useMutation({
|
api.schedule.delete.useMutation();
|
||||||
onSuccess: () => {
|
|
||||||
utils.schedule.list.invalidate({ applicationId });
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const { mutateAsync: runManually, isLoading } =
|
const { mutateAsync: runManually, isLoading } =
|
||||||
api.schedule.runManually.useMutation({
|
api.schedule.runManually.useMutation();
|
||||||
onSuccess: () => {
|
|
||||||
utils.schedule.list.invalidate({ applicationId });
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card className="border px-4 shadow-none bg-transparent">
|
<Card className="border px-4 shadow-none bg-transparent">
|
||||||
@@ -65,7 +57,9 @@ export const ShowSchedules = ({ applicationId }: Props) => {
|
|||||||
</CardDescription>
|
</CardDescription>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<HandleSchedules applicationId={applicationId} />
|
{schedules && schedules.length > 0 && (
|
||||||
|
<HandleSchedules applicationId={applicationId} />
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="px-0">
|
<CardContent className="px-0">
|
||||||
@@ -138,8 +132,12 @@ export const ShowSchedules = ({ applicationId }: Props) => {
|
|||||||
toast.success(
|
toast.success(
|
||||||
"Schedule run successfully",
|
"Schedule run successfully",
|
||||||
);
|
);
|
||||||
|
utils.schedule.list.invalidate({
|
||||||
|
applicationId,
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
console.log(error);
|
||||||
toast.error(
|
toast.error(
|
||||||
error instanceof Error
|
error instanceof Error
|
||||||
? error.message
|
? error.message
|
||||||
@@ -201,11 +199,15 @@ export const ShowSchedules = ({ applicationId }: Props) => {
|
|||||||
</Table>
|
</Table>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="flex flex-row gap-4 items-center justify-center py-12 border rounded-lg">
|
<div className="flex flex-col gap-2 items-center justify-center py-12 border rounded-lg">
|
||||||
<Clock className="size-6 text-muted-foreground" />
|
<Clock className="size-8 mb-4 text-muted-foreground" />
|
||||||
<p className="text-muted-foreground text-center">
|
<p className="text-lg font-medium text-muted-foreground">
|
||||||
No scheduled tasks found
|
No scheduled tasks
|
||||||
</p>
|
</p>
|
||||||
|
<p className="text-sm text-muted-foreground mt-1">
|
||||||
|
Create your first scheduled task to automate your workflows
|
||||||
|
</p>
|
||||||
|
<HandleSchedules applicationId={applicationId} />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</CardContent>
|
</CardContent>
|
||||||
|
|||||||
@@ -95,8 +95,16 @@ export const scheduleRouter = createTRPCRouter({
|
|||||||
runManually: protectedProcedure
|
runManually: protectedProcedure
|
||||||
.input(z.object({ scheduleId: z.string().min(1) }))
|
.input(z.object({ scheduleId: z.string().min(1) }))
|
||||||
.mutation(async ({ input }) => {
|
.mutation(async ({ input }) => {
|
||||||
await runCommand(input.scheduleId);
|
try {
|
||||||
|
await runCommand(input.scheduleId);
|
||||||
return true;
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
throw new TRPCError({
|
||||||
|
code: "INTERNAL_SERVER_ERROR",
|
||||||
|
message:
|
||||||
|
error instanceof Error ? error.message : "Error running schedule",
|
||||||
|
});
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user