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:
parent
ef02ba22b5
commit
1f6ba45c12
@ -39,18 +39,10 @@ export const ShowSchedules = ({ applicationId }: Props) => {
|
||||
const utils = api.useUtils();
|
||||
|
||||
const { mutateAsync: deleteSchedule, isLoading: isDeleting } =
|
||||
api.schedule.delete.useMutation({
|
||||
onSuccess: () => {
|
||||
utils.schedule.list.invalidate({ applicationId });
|
||||
},
|
||||
});
|
||||
api.schedule.delete.useMutation();
|
||||
|
||||
const { mutateAsync: runManually, isLoading } =
|
||||
api.schedule.runManually.useMutation({
|
||||
onSuccess: () => {
|
||||
utils.schedule.list.invalidate({ applicationId });
|
||||
},
|
||||
});
|
||||
api.schedule.runManually.useMutation();
|
||||
|
||||
return (
|
||||
<Card className="border px-4 shadow-none bg-transparent">
|
||||
@ -65,7 +57,9 @@ export const ShowSchedules = ({ applicationId }: Props) => {
|
||||
</CardDescription>
|
||||
</div>
|
||||
|
||||
<HandleSchedules applicationId={applicationId} />
|
||||
{schedules && schedules.length > 0 && (
|
||||
<HandleSchedules applicationId={applicationId} />
|
||||
)}
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent className="px-0">
|
||||
@ -138,8 +132,12 @@ export const ShowSchedules = ({ applicationId }: Props) => {
|
||||
toast.success(
|
||||
"Schedule run successfully",
|
||||
);
|
||||
utils.schedule.list.invalidate({
|
||||
applicationId,
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
toast.error(
|
||||
error instanceof Error
|
||||
? error.message
|
||||
@ -201,11 +199,15 @@ export const ShowSchedules = ({ applicationId }: Props) => {
|
||||
</Table>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex flex-row gap-4 items-center justify-center py-12 border rounded-lg">
|
||||
<Clock className="size-6 text-muted-foreground" />
|
||||
<p className="text-muted-foreground text-center">
|
||||
No scheduled tasks found
|
||||
<div className="flex flex-col gap-2 items-center justify-center py-12 border rounded-lg">
|
||||
<Clock className="size-8 mb-4 text-muted-foreground" />
|
||||
<p className="text-lg font-medium text-muted-foreground">
|
||||
No scheduled tasks
|
||||
</p>
|
||||
<p className="text-sm text-muted-foreground mt-1">
|
||||
Create your first scheduled task to automate your workflows
|
||||
</p>
|
||||
<HandleSchedules applicationId={applicationId} />
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
|
@ -95,8 +95,16 @@ export const scheduleRouter = createTRPCRouter({
|
||||
runManually: protectedProcedure
|
||||
.input(z.object({ scheduleId: z.string().min(1) }))
|
||||
.mutation(async ({ input }) => {
|
||||
await runCommand(input.scheduleId);
|
||||
|
||||
return true;
|
||||
try {
|
||||
await runCommand(input.scheduleId);
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
throw new TRPCError({
|
||||
code: "INTERNAL_SERVER_ERROR",
|
||||
message:
|
||||
error instanceof Error ? error.message : "Error running schedule",
|
||||
});
|
||||
}
|
||||
}),
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user