From 269f2f692657cd9e6307a82783bcbbaf0dff58d0 Mon Sep 17 00:00:00 2001 From: Pavlo Kulyk Date: Thu, 21 May 2026 15:45:35 +0300 Subject: [PATCH] fix: add error handling for job tasks and alert on job state error --- custom/JobInfoPopup.vue | 14 ++++++++++++++ index.ts | 4 +++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/custom/JobInfoPopup.vue b/custom/JobInfoPopup.vue index e72bbc5..29cd7db 100644 --- a/custom/JobInfoPopup.vue +++ b/custom/JobInfoPopup.vue @@ -67,6 +67,7 @@ import { getTimeAgoString, callAdminForthApi, getCustomComponent} from '@/utils' import { useI18n } from 'vue-i18n'; import StateToIcon from './StateToIcon.vue'; import { useAdminforth } from '@/adminforth'; +import { watch } from 'vue'; const { t } = useI18n(); @@ -133,6 +134,19 @@ async function getJobTasks(limit: number = 10, offset: number = 0): Promise<{sta } } +watch( + () => props.job.state?.error, + (error) => { + if (error) { + adminforth.alert({ + message: error, + variant: 'danger', + }); + } + }, + { immediate: true } +); + \ No newline at end of file diff --git a/index.ts b/index.ts index f42cc1f..c490b6e 100644 --- a/index.ts +++ b/index.ts @@ -279,7 +279,9 @@ export default class BackgroundJobsPlugin extends AdminForthPlugin { await this.setLevelDbTaskStatusField(jobLevelDb, taskIndex.toString(), 'DONE'); this.adminforth.websocket.publish(`/background-jobs-task-update/${jobId}`, { taskIndex, status: "DONE" }); } catch (error) { - afLogger.error(`Error in handling task ${taskIndex} of job ${jobId}: ${error}`, ); + const errorMessage = error?.message || 'Unknown error'; + afLogger.error(`Error in handling task ${taskIndex} of job ${jobId}: ${errorMessage}`, ); + await this.setJobField(jobId, 'error', errorMessage); await this.setLevelDbTaskStatusField(jobLevelDb, taskIndex.toString(), 'FAILED'); this.adminforth.websocket.publish(`/background-jobs-task-update/${jobId}`, { taskIndex, status: "FAILED" }); failedTasks++;