Skip to content

Commit

Permalink
fix hook error
Browse files Browse the repository at this point in the history
  • Loading branch information
tongchong committed Apr 28, 2024
1 parent ae15484 commit 4c92053
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
10 changes: 1 addition & 9 deletions apps/mis-server/src/services/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,15 +269,7 @@ export const jobServiceServer = plugin((server) => {
changeJobTimeLimit: async ({ request, logger }) => {
const { cluster, limitMinutes, jobId, operatorUserId } = request;

try {
await callHook("allowChangeJobTimeLimit", { cluster, limitMinutes, jobId, operatorUserId }, logger);
} catch (error) {
throw <ServiceError>{
code: Status.FAILED_PRECONDITION,
message: `The system does not allow you ${operatorUserId} to change the job`
+ ` with cluster ${cluster} jobid ${jobId} time limit.` + error,
};
}
await callHook("allowChangeJobTimeLimit", { cluster, limitMinutes, jobId, operatorUserId }, logger);

await server.ext.clusters.callOnOne(
cluster,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ export const ChangeJobTimeLimitModal: React.FC<Props> = ({ open, onClose, data,
if (e.code === "TIME_LIME_NOT_VALID") {
message.error(t(p("timeLimeError")));
};
if (e.code === "SYSTEM_UNALLOWED") {
message.error(e.message);
}
throw e;
})
.then(() => {
Expand Down
9 changes: 8 additions & 1 deletion apps/mis-web/src/pages/api/job/changeJobTimeLimit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ export const ChangeJobTimeLimitSchema = typeboxRouteSchema({
/** 作业未找到 */
404: Type.Null(),
/** 用户设置的时限错误 */
400: Type.Object({ code: Type.Literal("TIME_LIME_NOT_VALID") }),
400: Type.Object({
code: Type.Union([Type.Literal("TIME_LIME_NOT_VALID"), Type.Literal("SYSTEM_UNALLOWED")]),
message: Type.Optional(Type.String()),
}),
},
});

Expand Down Expand Up @@ -110,6 +113,10 @@ export default /* #__PURE__*/route(ChangeJobTimeLimitSchema,
})
.catch(handlegRPCError({
[Status.NOT_FOUND]: () => ({ 404: null }),
[Status.ALREADY_EXISTS]: (e) => ({ 400: {
code: "SYSTEM_UNALLOWED" as const,
message: e.message,
} }),
},
async () => await callLog(logInfo, OperationResult.FAIL),
));
Expand Down
8 changes: 7 additions & 1 deletion libs/hook/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,13 @@ export const createHookClient = (
event: { $case: eventName, [eventName]: eventPayload },
}).then(
() => { logger.debug("Hook call completed"); },
(e) => { logger.error(e, "Error when calling hook"); },
(e) => {
logger.error(e, "Error when calling hook");
// 如果是修改作业时限的hook,允许抛出错误
if (eventName === "allowChangeJobTimeLimit") {
throw e;
}
},
);
},
};
Expand Down

0 comments on commit 4c92053

Please sign in to comment.