Line data Source code
1 : <template>
2 1 : <div
3 : class="w-[300px] min-w-[260px] rounded-lg border bg-background shadow-md"
4 : >
5 : <div class="flex items-center border-b p-4">
6 : <span class="text-sm/normal font-normal text-foreground">{{
7 : t('queue.jobDetails.header')
8 : }}</span>
9 : </div>
10 : <div class="flex flex-col gap-6 p-4">
11 : <div
12 : class="grid grid-cols-2 items-center gap-2 text-xs/normal font-normal"
13 : >
14 2 : <template v-for="row in baseRows" :key="row.label">
15 : <div class="flex items-center text-foreground">
16 : {{ row.label }}
17 : </div>
18 : <div class="flex min-w-0 items-center text-muted-foreground">
19 : <span class="block min-w-0 truncate">{{ row.value }}</span>
20 : <Button
21 : v-if="row.canCopy"
22 : size="icon"
23 : variant="muted-textonly"
24 : :aria-label="copyAriaLabel"
25 : @click.stop="copyJobId"
26 : >
27 : <i class="icon-[lucide--copy]" />
28 : </Button>
29 : </div>
30 : </template>
31 : </div>
32 :
33 : <div
34 : v-if="extraRows.length"
35 : class="grid grid-cols-2 items-center gap-2 text-xs/normal font-normal"
36 : >
37 2 : <template v-for="row in extraRows" :key="row.label">
38 : <div class="flex items-center text-foreground">
39 : {{ row.label }}
40 : </div>
41 : <div class="flex min-w-0 items-center text-muted-foreground">
42 : <span class="block min-w-0 truncate">{{ row.value }}</span>
43 : </div>
44 : </template>
45 : </div>
46 :
47 : <div v-if="jobState === 'failed'" class="grid grid-cols-2 gap-x-2">
48 : <div
49 : class="flex items-center text-xs/normal font-normal text-foreground"
50 : >
51 : {{ t('queue.jobDetails.errorMessage') }}
52 : </div>
53 : <div class="flex items-center justify-between gap-4">
54 : <Button
55 : class="justify-start px-0"
56 : variant="muted-textonly"
57 : size="sm"
58 : icon-position="right"
59 : @click.stop="copyErrorMessage"
60 : >
61 : <span>{{ copyAriaLabel }}</span>
62 : <i class="icon-[lucide--copy] block size-3.5 leading-none" />
63 : </Button>
64 : <Button
65 : class="justify-start px-0"
66 : variant="muted-textonly"
67 : size="sm"
68 : icon-position="right"
69 : @click.stop="reportJobError"
70 : >
71 : <span>{{ t('queue.jobDetails.report') }}</span>
72 : <i
73 : class="icon-[lucide--message-circle-warning] block size-3.5 leading-none"
74 : />
75 : </Button>
76 : </div>
77 : <div
78 : class="col-span-2 mt-2 max-h-96 overflow-y-auto rounded-sm bg-accent px-4 py-2 text-xs/normal wrap-break-word whitespace-pre-wrap text-muted-foreground"
79 : >
80 : {{ errorMessageValue }}
81 : </div>
82 : </div>
83 : </div>
84 : </div>
85 : </template>
86 :
87 : <script setup lang="ts">
88 : import { computed, onMounted, onUnmounted, ref } from 'vue'
89 : import { useI18n } from 'vue-i18n'
90 :
91 : import Button from '@comfyorg/design-system/button/Button'
92 : import { useCopyToClipboard } from '@/composables/useCopyToClipboard'
93 : import { isCloud } from '@/platform/distribution/types'
94 : import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore'
95 : import { useDialogService } from '@/services/dialogService'
96 : import { useExecutionStore } from '@/stores/executionStore'
97 : import { useQueueStore } from '@/stores/queueStore'
98 : import type { TaskItemImpl } from '@/stores/queueStore'
99 : import { formatClockTime } from '@/utils/dateTimeUtil'
100 : import { jobStateFromTask } from '@/utils/queueUtil'
101 :
102 : import { useJobErrorReporting } from './useJobErrorReporting'
103 : import { formatElapsedTime, useQueueEstimates } from './useQueueEstimates'
104 :
105 1 : const props = defineProps<{
106 : jobId: string
107 : workflowId?: string
108 : }>()
109 :
110 1 : const copyAriaLabel = computed(() => t('g.copy'))
111 :
112 1 : const workflowStore = useWorkflowStore()
113 1 : const queueStore = useQueueStore()
114 1 : const executionStore = useExecutionStore()
115 1 : const dialog = useDialogService()
116 1 : const { locale, t } = useI18n()
117 :
118 1 : const workflowValue = computed(() => {
119 1 : const wid = props.workflowId
120 1 : if (!wid) return ''
121 1 : const activeId = workflowStore.activeWorkflow?.activeState?.id
122 1 : if (activeId && activeId === wid) {
123 0 : return workflowStore.activeWorkflow?.filename ?? wid
124 : }
125 0 : return wid
126 : })
127 1 : const jobIdValue = computed(() => props.jobId)
128 :
129 1 : const { copyToClipboard } = useCopyToClipboard()
130 1 : const copyJobId = () => void copyToClipboard(jobIdValue.value)
131 :
132 1 : const taskForJob = computed(() => {
133 1 : const pid = props.jobId
134 1 : const findIn = (arr: TaskItemImpl[]) =>
135 : arr.find((t) => String(t.jobId ?? '') === String(pid))
136 1 : return (
137 : findIn(queueStore.pendingTasks) ||
138 : findIn(queueStore.runningTasks) ||
139 : findIn(queueStore.historyTasks) ||
140 : null
141 : )
142 : })
143 :
144 1 : const jobState = computed(() => {
145 1 : const task = taskForJob.value
146 1 : if (!task) return null
147 : const isInitializing = executionStore.isJobInitializing(String(task?.jobId))
148 1 : return jobStateFromTask(task, isInitializing)
149 : })
150 :
151 1 : const firstSeenTs = computed<number | undefined>(() => {
152 : const task = taskForJob.value
153 1 : return task?.createTime
154 : })
155 :
156 1 : const queuedAtValue = computed(() =>
157 : firstSeenTs.value !== undefined
158 : ? formatClockTime(firstSeenTs.value, locale.value)
159 : : ''
160 : )
161 :
162 1 : const currentJobPriority = computed<number | null>(() => {
163 0 : const task = taskForJob.value
164 0 : return task ? Number(task.job.priority) : null
165 : })
166 :
167 1 : const jobsAhead = computed<number | null>(() => {
168 0 : const idx = currentJobPriority.value
169 0 : if (idx == null) return null
170 : const ahead = queueStore.pendingTasks.filter(
171 : (t: TaskItemImpl) => Number(t.job.priority) < idx
172 : )
173 0 : return ahead.length
174 : })
175 :
176 1 : const queuePositionValue = computed(() => {
177 0 : if (jobsAhead.value == null) return ''
178 0 : const n = jobsAhead.value
179 0 : return t('queue.jobDetails.queuePositionValue', { count: n }, n)
180 : })
181 :
182 1 : const nowTs = ref<number>(Date.now())
183 1 : let timer: number | null = null
184 1 : onMounted(() => {
185 1 : timer = window.setInterval(() => {
186 0 : nowTs.value = Date.now()
187 : }, 1000)
188 : })
189 1 : onUnmounted(() => {
190 0 : if (timer != null) {
191 0 : clearInterval(timer)
192 0 : timer = null
193 : }
194 : })
195 :
196 1 : const {
197 : showParallelQueuedStats,
198 : estimateRangeSeconds,
199 : estimateRemainingRangeSeconds,
200 : timeElapsedValue
201 : } = useQueueEstimates({
202 : queueStore,
203 : executionStore,
204 : taskForJob,
205 : jobState,
206 : firstSeenTs,
207 : jobsAhead,
208 : nowTs
209 : })
210 :
211 1 : const formatEta = (lo: number, hi: number): string => {
212 0 : if (hi <= 60) {
213 0 : const hiS = Math.max(1, Math.round(hi))
214 0 : const loS = Math.max(1, Math.min(hiS, Math.round(lo)))
215 0 : if (loS === hiS)
216 0 : return t('queue.jobDetails.eta.seconds', { count: hiS }, hiS)
217 0 : return t('queue.jobDetails.eta.secondsRange', { lo: loS, hi: hiS })
218 : }
219 0 : if (lo >= 60 && hi < 90) {
220 0 : return t('queue.jobDetails.eta.minutes', { count: 1 }, 1)
221 : }
222 0 : const loM = Math.max(1, Math.floor(lo / 60))
223 0 : const hiM = Math.max(loM, Math.ceil(hi / 60))
224 0 : if (loM === hiM) {
225 0 : return t('queue.jobDetails.eta.minutes', { count: loM }, loM)
226 : }
227 0 : return t('queue.jobDetails.eta.minutesRange', { lo: loM, hi: hiM })
228 : }
229 :
230 1 : const estimatedStartInValue = computed(() => {
231 0 : const range = estimateRangeSeconds.value
232 0 : if (!range) return ''
233 0 : const [lo, hi] = range
234 0 : return formatEta(lo, hi)
235 : })
236 :
237 1 : const estimatedFinishInValue = computed(() => {
238 0 : const range = estimateRemainingRangeSeconds.value
239 0 : if (!range) return ''
240 0 : const [lo, hi] = range
241 0 : return formatEta(lo, hi)
242 : })
243 :
244 : type DetailRow = { label: string; value: string; canCopy?: boolean }
245 :
246 1 : const baseRows = computed<DetailRow[]>(() => [
247 : { label: t('queue.jobDetails.workflow'), value: workflowValue.value },
248 : { label: t('queue.jobDetails.jobId'), value: jobIdValue.value, canCopy: true }
249 : ])
250 :
251 1 : const extraRows = computed<DetailRow[]>(() => {
252 1 : if (jobState.value === 'pending') {
253 0 : if (!firstSeenTs.value) return []
254 0 : const rows: DetailRow[] = [
255 : { label: t('queue.jobDetails.queuedAt'), value: queuedAtValue.value }
256 : ]
257 0 : if (showParallelQueuedStats.value) {
258 0 : rows.push(
259 : {
260 : label: t('queue.jobDetails.queuePosition'),
261 : value: queuePositionValue.value
262 : },
263 : {
264 : label: t('queue.jobDetails.timeElapsed'),
265 : value: timeElapsedValue.value
266 : },
267 : {
268 : label: t('queue.jobDetails.estimatedStartIn'),
269 : value: estimatedStartInValue.value
270 : }
271 : )
272 : }
273 0 : return rows
274 : }
275 1 : if (jobState.value === 'running') {
276 0 : if (!firstSeenTs.value) return []
277 0 : return [
278 : { label: t('queue.jobDetails.queuedAt'), value: queuedAtValue.value },
279 : {
280 : label: t('queue.jobDetails.timeElapsed'),
281 : value: timeElapsedValue.value
282 : },
283 : {
284 : label: t('queue.jobDetails.estimatedFinishIn'),
285 : value: estimatedFinishInValue.value
286 : }
287 : ]
288 : }
289 1 : if (jobState.value === 'completed') {
290 0 : const task = taskForJob.value
291 0 : const endTs: number | undefined = task?.executionEndTimestamp
292 0 : const execMs: number | undefined = task?.executionTime
293 0 : const generatedOnValue = endTs ? formatClockTime(endTs, locale.value) : ''
294 0 : const totalGenTimeValue =
295 : execMs !== undefined ? formatElapsedTime(execMs) : ''
296 : const computeHoursValue =
297 0 : execMs !== undefined ? (execMs / 3600000).toFixed(3) + ' hours' : ''
298 :
299 : const rows: DetailRow[] = [
300 : { label: t('queue.jobDetails.generatedOn'), value: generatedOnValue },
301 : {
302 : label: t('queue.jobDetails.totalGenerationTime'),
303 : value: totalGenTimeValue
304 : }
305 : ]
306 : if (isCloud) {
307 : rows.push({
308 : label: t('queue.jobDetails.computeHoursUsed'),
309 : value: computeHoursValue
310 : })
311 : }
312 0 : return rows
313 : }
314 1 : if (jobState.value === 'failed') {
315 : const task = taskForJob.value
316 1 : const execMs: number | undefined = task?.executionTime
317 1 : const failedAfterValue =
318 : execMs !== undefined ? formatElapsedTime(execMs) : ''
319 : const computeHoursValue =
320 1 : execMs !== undefined ? (execMs / 3600000).toFixed(3) + ' hours' : ''
321 : const rows: DetailRow[] = [
322 : { label: t('queue.jobDetails.queuedAt'), value: queuedAtValue.value },
323 : { label: t('queue.jobDetails.failedAfter'), value: failedAfterValue }
324 : ]
325 : if (isCloud) {
326 : rows.push({
327 : label: t('queue.jobDetails.computeHoursUsed'),
328 : value: computeHoursValue
329 : })
330 : }
331 1 : return rows
332 : }
333 0 : return []
334 : })
335 :
336 1 : const { errorMessageValue, copyErrorMessage, reportJobError } =
337 : useJobErrorReporting({
338 : taskForJob,
339 : copyToClipboard,
340 : dialog
341 : })
342 : </script>
|