Skip to content

Commit 269f2f6

Browse files
committed
fix: add error handling for job tasks and alert on job state error
1 parent fa4a723 commit 269f2f6

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

custom/JobInfoPopup.vue

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ import { getTimeAgoString, callAdminForthApi, getCustomComponent} from '@/utils'
6767
import { useI18n } from 'vue-i18n';
6868
import StateToIcon from './StateToIcon.vue';
6969
import { useAdminforth } from '@/adminforth';
70+
import { watch } from 'vue';
7071
7172
7273
const { t } = useI18n();
@@ -133,6 +134,19 @@ async function getJobTasks(limit: number = 10, offset: number = 0): Promise<{sta
133134
}
134135
}
135136
137+
watch(
138+
() => props.job.state?.error,
139+
(error) => {
140+
if (error) {
141+
adminforth.alert({
142+
message: error,
143+
variant: 'danger',
144+
});
145+
}
146+
},
147+
{ immediate: true }
148+
);
149+
136150
137151
138152
</script>

index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,9 @@ export default class BackgroundJobsPlugin extends AdminForthPlugin {
279279
await this.setLevelDbTaskStatusField(jobLevelDb, taskIndex.toString(), 'DONE');
280280
this.adminforth.websocket.publish(`/background-jobs-task-update/${jobId}`, { taskIndex, status: "DONE" });
281281
} catch (error) {
282-
afLogger.error(`Error in handling task ${taskIndex} of job ${jobId}: ${error}`, );
282+
const errorMessage = error?.message || 'Unknown error';
283+
afLogger.error(`Error in handling task ${taskIndex} of job ${jobId}: ${errorMessage}`, );
284+
await this.setJobField(jobId, 'error', errorMessage);
283285
await this.setLevelDbTaskStatusField(jobLevelDb, taskIndex.toString(), 'FAILED');
284286
this.adminforth.websocket.publish(`/background-jobs-task-update/${jobId}`, { taskIndex, status: "FAILED" });
285287
failedTasks++;

0 commit comments

Comments
 (0)