|
23 | 23 | import TypeFiltersFlowModal from '$lib/components/v2/workflow/TypeFiltersFlowModal.svelte'; |
24 | 24 | import { slide } from 'svelte/transition'; |
25 | 25 | import ImagesStatusModal from '$lib/components/jobs/ImagesStatusModal.svelte'; |
| 26 | + import JobStatusIcon from '$lib/components/jobs/JobStatusIcon.svelte'; |
26 | 27 |
|
27 | 28 | /** @type {import('fractal-components/types/api').WorkflowV2} */ |
28 | 29 | let workflow = $page.data.workflow; |
|
36 | 37 | /** @type {number|undefined} */ |
37 | 38 | let selectedDatasetId = undefined; |
38 | 39 |
|
| 40 | + let isLegacy = false; |
| 41 | + /** @type {{[key: number]: import('fractal-components/types/api').JobStatus}} */ |
| 42 | + let legacyStatuses = {}; |
| 43 | +
|
39 | 44 | let jobError = ''; |
40 | 45 | /** @type {import('fractal-components/types/api').ApplyWorkflowV2|undefined} */ |
41 | 46 | let failedJob; |
|
482 | 487 | selectedSubmittedJob = undefined; |
483 | 488 | return; |
484 | 489 | } |
485 | | - selectedSubmittedJob = await getSelectedSubmittedJob(selectedDatasetId); |
486 | | - const outputStatusResponse = await fetch( |
| 490 | + selectedSubmittedJob = await getSelectedJob(selectedDatasetId); |
| 491 | + const statusResponse = await fetch( |
487 | 492 | `/api/v2/project/${workflow.project_id}/status?dataset_id=${selectedDatasetId}&workflow_id=${workflow.id}`, |
488 | 493 | { |
489 | 494 | method: 'GET', |
490 | 495 | credentials: 'include' |
491 | 496 | } |
492 | 497 | ); |
493 | | - const outputStatus = await outputStatusResponse.json(); |
494 | | - if (!outputStatusResponse.ok) { |
495 | | - console.error('Error retrieving images status', outputStatus); |
| 498 | + const receivedStatuses = await statusResponse.json(); |
| 499 | + if (!statusResponse.ok) { |
| 500 | + console.error('Error retrieving images status', receivedStatuses); |
496 | 501 | return; |
497 | 502 | } |
498 | 503 | const jobHasError = selectedSubmittedJob?.status === 'failed'; |
499 | | - statuses = Object.fromEntries(Object.entries(outputStatus).filter(([, v]) => v !== null)); |
| 504 | + statuses = Object.fromEntries(Object.entries(receivedStatuses).filter(([, v]) => v !== null)); |
| 505 | + if (selectedSubmittedJob && Object.keys(statuses).length === 0) { |
| 506 | + await loadLegacyStatus(); |
| 507 | + } else { |
| 508 | + isLegacy = false; |
| 509 | + } |
500 | 510 | const submitted = Object.values(statuses).filter((s) => s.num_submitted_images > 0); |
501 | 511 | if (submitted.length > 0 || selectedSubmittedJob?.status === 'submitted') { |
502 | 512 | window.clearTimeout(statusWatcherTimer); |
|
511 | 521 | await loadJobError(jobHasError); |
512 | 522 | } |
513 | 523 |
|
| 524 | + async function loadLegacyStatus() { |
| 525 | + const response = await fetch( |
| 526 | + `/api/v2/project/1/status-legacy?workflow_id=${workflow.id}&dataset_id=${selectedDatasetId}` |
| 527 | + ); |
| 528 | + if (!response.ok) { |
| 529 | + console.log('Error loading legacy status'); |
| 530 | + return; |
| 531 | + } |
| 532 | + const result = await response.json(); |
| 533 | + if (Object.keys(result).length === 0) { |
| 534 | + return; |
| 535 | + } |
| 536 | + legacyStatuses = result.status; |
| 537 | + isLegacy = true; |
| 538 | + } |
| 539 | +
|
514 | 540 | async function reloadSelectedDataset() { |
515 | 541 | if (selectedDatasetId === undefined) { |
516 | 542 | return; |
|
574 | 600 | * @param {number} datasetId |
575 | 601 | * @return {Promise<import('fractal-components/types/api').ApplyWorkflowV2|undefined>} |
576 | 602 | */ |
577 | | - async function getSelectedSubmittedJob(datasetId) { |
| 603 | + async function getSelectedJob(datasetId) { |
578 | 604 | const submitted = Object.values(statuses).filter((s) => s.num_submitted_images > 0); |
579 | 605 | if ( |
580 | 606 | submitted.length > 0 && |
|
856 | 882 | {workflowTask.task.name} |
857 | 883 | <span class="float-end ps-2"> |
858 | 884 | {#if selectedDatasetId} |
859 | | - <ImagesStatus |
860 | | - status={statuses[workflowTask.id]} |
861 | | - datasetId={selectedDatasetId} |
862 | | - projectId={project.id} |
863 | | - workflowTaskId={workflowTask.id} |
864 | | - {imagesStatusModal} |
865 | | - /> |
| 885 | + {#if isLegacy} |
| 886 | + <JobStatusIcon status={legacyStatuses[workflowTask.id]} /> |
| 887 | + {:else} |
| 888 | + <ImagesStatus |
| 889 | + status={statuses[workflowTask.id]} |
| 890 | + datasetId={selectedDatasetId} |
| 891 | + projectId={project.id} |
| 892 | + workflowTaskId={workflowTask.id} |
| 893 | + {imagesStatusModal} |
| 894 | + /> |
| 895 | + {/if} |
866 | 896 | {/if} |
867 | 897 | </span> |
868 | 898 | {#if newVersionsMap[workflowTask.task.id]?.length > 0} |
|
0 commit comments