-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathWorkflowInvocationState.vue
More file actions
580 lines (535 loc) · 22 KB
/
WorkflowInvocationState.vue
File metadata and controls
580 lines (535 loc) · 22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
<script setup lang="ts">
import {
faAngleDoubleDown,
faAngleDoubleUp,
faExclamation,
faSpinner,
faSquare,
} from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
import { BAlert, BBadge, BNav, BNavItem } from "bootstrap-vue";
import { computed, onUnmounted, ref, watch } from "vue";
import { type InvocationStep, isWorkflowInvocationElementView } from "@/api/invocations";
import { usePersistentToggle } from "@/composables/persistentToggle";
import { useInvocationStore } from "@/stores/invocationStore";
import { useWorkflowStore } from "@/stores/workflowStore";
import { errorMessageAsString } from "@/utils/simple-error";
import {
errorCount as jobStatesSummaryErrorCount,
isTerminal,
jobCount as jobStatesSummaryJobCount,
numTerminal,
okCount as jobStatesSummaryOkCount,
runningCount as jobStatesSummaryRunningCount,
} from "./util";
import GButton from "../BaseComponents/GButton.vue";
import ProgressBar from "../ProgressBar.vue";
import WorkflowInvocationSteps from "../Workflow/Invocation/Graph/WorkflowInvocationSteps.vue";
import InvocationReport from "../Workflow/InvocationReport.vue";
import WorkflowAnnotation from "../Workflow/WorkflowAnnotation.vue";
import WorkflowNavigationTitle from "../Workflow/WorkflowNavigationTitle.vue";
import TabsDisabledAlert from "./TabsDisabledAlert.vue";
import WorkflowInvocationExportOptions from "./WorkflowInvocationExportOptions.vue";
import WorkflowInvocationFeedback from "./WorkflowInvocationFeedback.vue";
import WorkflowInvocationInputOutputTabs from "./WorkflowInvocationInputOutputTabs.vue";
import WorkflowInvocationMetrics from "./WorkflowInvocationMetrics.vue";
import WorkflowInvocationOverview from "./WorkflowInvocationOverview.vue";
import WorkflowInvocationSearch from "./WorkflowInvocationSearch.vue";
import WorkflowInvocationShare from "./WorkflowInvocationShare.vue";
import LoadingSpan from "@/components/LoadingSpan.vue";
type InvocationViewTab = "steps" | "inputs" | "outputs" | "report" | "export" | "metrics" | "debug";
interface Props {
invocationId: string;
tab?: InvocationViewTab;
isSubworkflow?: boolean;
isFullPage?: boolean;
success?: boolean;
}
const props = withDefaults(defineProps<Props>(), {
tab: undefined,
isSubworkflow: false,
});
const emit = defineEmits<{
(e: "invocation-cancelled"): void;
}>();
const invocationStore = useInvocationStore();
const stepStatesInterval = ref<any>(undefined);
const jobStatesInterval = ref<any>(undefined);
const invocationLoaded = ref(false);
const errorMessage = ref<string | null>(null);
const cancellingInvocation = ref(false);
const isPolling = ref(false);
const { toggled: headerCollapsed, toggle: toggleHeaderCollapse } = usePersistentToggle("invocation-header-collapsed");
const uniqueMessages = computed(() => {
const messages = invocation.value?.messages || [];
const uniqueMessagesSet = new Set(messages.map((message) => JSON.stringify(message)));
return Array.from(uniqueMessagesSet).map((message) => JSON.parse(message)) as typeof messages;
});
const workflowStore = useWorkflowStore();
const tabsDisabled = computed(
() =>
!invocationStateSuccess.value ||
!invocation.value ||
!workflowStore.getStoredWorkflowByInstanceId(invocation.value.workflow_id),
);
/** Tooltip message for the a tab when it is disabled */
const disabledTabTooltip = computed(() => {
const state = invocationState.value;
if (state != "scheduled") {
return `This workflow is not currently scheduled. The current state is ${state}. Disabled tabs are available if the workflow is fully scheduled and all jobs have completed.`;
} else if (stateCounts.value && stateCounts.value.runningCount != 0) {
return `The workflow invocation still contains ${stateCounts.value.runningCount} running job(s). Once these jobs have completed any disabled tabs will become available.`;
} else {
return "Steps for this workflow are still running. Any disabled tabs will be available once complete.";
}
});
/** We are on the default "Overview" tab if the tab prop is not set or is not one of the expected tab values */
const onOverviewTab = computed(() => {
return !props.tab || !["steps", "inputs", "outputs", "report", "export", "metrics", "debug"].includes(props.tab);
});
const invocation = computed(() => {
const storedInvocation = invocationStore.getInvocationById(props.invocationId);
if (invocationLoaded.value && isWorkflowInvocationElementView(storedInvocation)) {
return storedInvocation;
} else {
return null;
}
});
const invocationState = computed(() => invocation.value?.state || "new");
const invocationAndJobTerminal = computed(() => invocationSchedulingTerminal.value && jobStatesTerminal.value);
const invocationSchedulingTerminal = computed(() => {
return (
invocationState.value == "scheduled" ||
invocationState.value == "cancelled" ||
invocationState.value == "failed" ||
invocationState.value == "completed"
);
});
const jobStatesTerminal = computed(() => {
// If the job states summary is null, we haven't fetched it yet
// If the `populated_state` for the summary is `new`, we haven't finished scheduling all jobs
if (jobStatesSummary.value === null || jobStatesSummary.value.populated_state === "new") {
return false;
}
if (invocationSchedulingTerminal.value && jobCount.value === 0) {
// no jobs for this invocation (think it has just subworkflows/inputs)
return true;
}
return isTerminal(jobStatesSummary.value);
});
const jobStatesSummary = computed(() => invocationStore.getInvocationJobsSummaryById(props.invocationId));
/** The job summary for each step in the invocation */
const stepsJobsSummary = computed(() => {
return invocationStore.getInvocationStepJobsSummaryById(props.invocationId);
});
const invocationStateSuccess = computed(() => {
return (
(invocationState.value == "scheduled" || invocationState.value == "completed") &&
stateCounts.value?.runningCount === 0 &&
invocationAndJobTerminal.value
);
});
const canSubmitFeedback = computed(
() =>
invocationAndJobTerminal.value &&
(invocationState.value === "failed" || Boolean(stateCounts.value?.errorCount)),
);
type StepStateType = { [state: string]: number };
const stepStates = computed<StepStateType>(() => {
const stepStates: StepStateType = {};
const steps: InvocationStep[] = invocation.value?.steps || [];
for (const step of steps) {
if (!step) {
continue;
}
// the API defined state here allowing null and undefined is odd...
const stepState: string = step.state || "unknown";
if (!stepStates[stepState]) {
stepStates[stepState] = 1;
} else {
stepStates[stepState] += 1;
}
}
return stepStates;
});
const stepCount = computed<number>(() => {
return invocation.value?.steps.length || 0;
});
const stepStatesStr = computed<string>(() => {
return `${stepStates.value?.scheduled || 0} of ${stepCount.value} steps successfully scheduled.`;
});
const stateCounts = computed<{
okCount: number;
errorCount: number;
runningCount: number;
newCount: number;
} | null>(() => {
if (jobStatesSummary.value === null) {
return null;
}
const okCount = jobStatesSummaryOkCount(jobStatesSummary.value);
const errorCount = jobStatesSummaryErrorCount(jobStatesSummary.value);
const runningCount = jobStatesSummaryRunningCount(jobStatesSummary.value);
const newCount = jobCount.value - okCount - runningCount - errorCount;
return { okCount, errorCount, runningCount, newCount };
});
const jobCount = computed<number>(() => {
return jobStatesSummaryJobCount(jobStatesSummary.value);
});
const jobStatesStr = computed(() => {
if (jobStatesSummary.value === null) {
return "No jobs summary available yet.";
}
let jobStr = `${numTerminal(jobStatesSummary.value) || 0} of ${jobCount.value} jobs complete`;
if (!invocationSchedulingTerminal.value) {
jobStr += " (total number of jobs will change until all steps fully scheduled)";
}
return `${jobStr}.`;
});
watch(
() => props.invocationId,
async (id) => {
// Prevent the page from reloading when you switch tabs. We set the boolean as soon as we know that
// the invocation exists in the store, and with this, when we change tabs there isn't a refresh every time.
const storedInvocation = invocationStore.getInvocationById(id);
if (storedInvocation && isWorkflowInvocationElementView(storedInvocation)) {
invocationLoaded.value = true;
} else {
invocationLoaded.value = false;
}
try {
await invocationStore.fetchInvocationById({ id });
invocationLoaded.value = true;
// Only start polling if there is a valid invocation
if (invocation.value) {
await pollStepStatesUntilTerminal();
await pollJobStatesUntilTerminal();
}
} catch (e) {
errorMessage.value = errorMessageAsString(e);
}
},
{ immediate: true },
);
watch(
() => invocationSchedulingTerminal.value,
async (newVal, oldVal) => {
if (oldVal && !newVal) {
// If the invocation was terminal and now is not, start polling again
await pollStepStatesUntilTerminal();
}
},
);
// If a workflow is run just now (success prop), we want to have the header expanded
watch(
() => props.success,
(success) => {
if (success && headerCollapsed.value) {
setTimeout(() => {
headerCollapsed.value = false;
}, 1500);
}
},
{ immediate: true },
);
onUnmounted(() => {
clearTimeout(stepStatesInterval.value);
clearTimeout(jobStatesInterval.value);
});
async function pollStepStatesUntilTerminal() {
if (!invocationSchedulingTerminal.value) {
await invocationStore.fetchInvocationById({ id: props.invocationId });
stepStatesInterval.value = setTimeout(pollStepStatesUntilTerminal, 3000);
}
}
async function pollJobStatesUntilTerminal() {
if (!jobStatesTerminal.value && invocation.value) {
isPolling.value = true;
await invocationStore.fetchInvocationJobsSummaryForId({ id: props.invocationId });
await invocationStore.fetchInvocationStepJobsSummaryForId({ id: props.invocationId });
jobStatesInterval.value = setTimeout(pollJobStatesUntilTerminal, 3000);
} else {
isPolling.value = false;
}
}
function onError(e: any) {
console.error(e);
}
async function onCancel() {
try {
cancellingInvocation.value = true;
await invocationStore.cancelWorkflowScheduling(props.invocationId);
} catch (e) {
onError(e);
} finally {
emit("invocation-cancelled");
cancellingInvocation.value = false;
}
}
</script>
<template>
<div v-if="invocation" class="d-flex flex-column w-100" data-description="workflow invocation state">
<WorkflowNavigationTitle
v-if="props.isFullPage"
:invocation="invocation"
:workflow-id="invocation.workflow_id"
:success="props.success">
<template v-slot:before-icon>
<GButton
transparent
size="small"
:title="headerCollapsed ? 'Expand header' : 'Collapse header'"
icon-only
inline
@click="toggleHeaderCollapse">
<FontAwesomeIcon :icon="headerCollapsed ? faAngleDoubleDown : faAngleDoubleUp" fixed-width />
</GButton>
</template>
<template v-slot:workflow-title-actions>
<GButton
v-if="!invocationAndJobTerminal"
title="Cancel scheduling of workflow invocation"
tooltip
data-description="header cancel invocation button"
size="small"
transparent
color="blue"
:disabled="cancellingInvocation || invocationState == 'cancelling'"
@click="onCancel">
<FontAwesomeIcon :icon="faSquare" fixed-width />
Cancel
</GButton>
<WorkflowInvocationShare
:invocation-id="invocation.id"
:workflow-id="invocation.workflow_id"
:history-id="invocation.history_id" />
</template>
</WorkflowNavigationTitle>
<Transition name="header-collapse">
<WorkflowAnnotation
v-if="props.isFullPage && !headerCollapsed"
:workflow-id="invocation.workflow_id"
:invocation-create-time="invocation.create_time"
:history-id="invocation.history_id">
<template v-slot:middle-content>
<div class="progress-bars mx-1">
<ProgressBar
v-if="!stepCount"
note="Loading step state summary..."
:loading="true"
class="steps-progress" />
<ProgressBar
v-else-if="invocationState == 'cancelled'"
note="Invocation scheduling cancelled - expected jobs and outputs may not be generated."
:error-count="1"
class="steps-progress" />
<ProgressBar
v-else-if="invocationState == 'failed'"
note="Invocation scheduling failed - Galaxy administrator may have additional details in logs."
:error-count="1"
class="steps-progress" />
<ProgressBar
v-else
:note="stepStatesStr"
:total="stepCount"
:ok-count="stepStates.scheduled"
:loading="!invocationSchedulingTerminal"
class="steps-progress" />
<ProgressBar
v-if="stateCounts"
:note="jobStatesStr"
:total="jobCount"
:ok-count="stateCounts.okCount"
:running-count="stateCounts.runningCount"
:new-count="stateCounts.newCount"
:error-count="stateCounts.errorCount"
:loading="!invocationAndJobTerminal"
class="jobs-progress" />
</div>
</template>
</WorkflowAnnotation>
</Transition>
<BNav v-if="props.isFullPage" pills class="mb-2 p-2 bg-light border-bottom">
<BNavItem title="Overview" :active="onOverviewTab" :to="`/workflows/invocations/${props.invocationId}`">
Overview
</BNavItem>
<BNavItem
title="Steps"
:active="props.tab === 'steps'"
:to="`/workflows/invocations/${props.invocationId}/steps`">
Steps
</BNavItem>
<BNavItem
title="Inputs"
:active="props.tab === 'inputs'"
:to="`/workflows/invocations/${props.invocationId}/inputs`">
Inputs
</BNavItem>
<BNavItem
title="Outputs"
:active="props.tab === 'outputs'"
:to="`/workflows/invocations/${props.invocationId}/outputs`">
Outputs
</BNavItem>
<BNavItem
:title="!tabsDisabled ? 'Report' : disabledTabTooltip"
class="invocation-report-tab"
:active="!tabsDisabled && props.tab === 'report'"
:to="`/workflows/invocations/${props.invocationId}/report`"
:disabled="tabsDisabled">
Report
</BNavItem>
<BNavItem
:title="!tabsDisabled ? 'Export' : disabledTabTooltip"
class="invocation-export-tab"
:active="!tabsDisabled && props.tab === 'export'"
:to="`/workflows/invocations/${props.invocationId}/export`"
:disabled="tabsDisabled">
Export
</BNavItem>
<BNavItem
title="Metrics"
:active="props.tab === 'metrics'"
:to="`/workflows/invocations/${props.invocationId}/metrics`">
Metrics
</BNavItem>
<BNavItem
v-if="canSubmitFeedback && stepsJobsSummary"
title="Debug"
class="invocation-debug-tab"
:active="props.tab === 'debug'"
:to="`/workflows/invocations/${props.invocationId}/debug`">
Debug
</BNavItem>
<div class="ml-auto d-flex align-items-center flex-gapx-1">
<WorkflowInvocationSearch
v-if="!props.tab"
:invocation-id="props.invocationId"
:workflow-id="invocation.workflow_id" />
<BBadge v-if="tabsDisabled" v-g-tooltip.hover :title="disabledTabTooltip" variant="primary">
<FontAwesomeIcon :icon="faExclamation" />
</BBadge>
<BBadge v-if="isPolling" v-g-tooltip.hover title="Polling for updates" variant="link">
<FontAwesomeIcon :icon="faSpinner" spin />
</BBadge>
</div>
</BNav>
<div class="mt-1 d-flex flex-column overflow-auto tab-content-container">
<div v-if="onOverviewTab">
<WorkflowInvocationOverview
class="invocation-overview"
:invocation="invocation"
:steps-jobs-summary="stepsJobsSummary || undefined"
:is-full-page="props.isFullPage"
:invocation-and-job-terminal="invocationAndJobTerminal"
:is-subworkflow="isSubworkflow"
:invocation-messages="uniqueMessages" />
</div>
<div v-if="props.tab === 'steps'" class="steps-tab-content">
<BAlert v-if="isSubworkflow" variant="info" show>
<span v-localize>Subworkflow steps are not available.</span>
</BAlert>
<WorkflowInvocationSteps
v-else-if="invocation && stepsJobsSummary"
:invocation="invocation"
:steps-jobs-summary="stepsJobsSummary"
:is-full-page="props.isFullPage" />
</div>
<WorkflowInvocationInputOutputTabs
v-if="props.tab === 'inputs' || props.tab === 'outputs'"
:invocation="invocation"
:terminal="invocationAndJobTerminal"
:tab="props.tab" />
<div v-if="props.tab === 'report'">
<BAlert v-if="isSubworkflow" variant="info" show>
<span v-localize>Report is not available for subworkflow.</span>
</BAlert>
<TabsDisabledAlert
v-else-if="tabsDisabled"
:invocation-id="props.invocationId"
:tooltip="disabledTabTooltip" />
<InvocationReport v-else :invocation-id="invocation.id" />
</div>
<div v-if="props.tab === 'export'">
<TabsDisabledAlert
v-if="tabsDisabled"
:invocation-id="props.invocationId"
:tooltip="disabledTabTooltip" />
<div v-else>
<WorkflowInvocationExportOptions :invocation-id="invocation.id" />
</div>
</div>
<div v-if="props.tab === 'metrics'">
<WorkflowInvocationMetrics :invocation-id="invocation.id" :not-terminal="!invocationAndJobTerminal" />
</div>
<div v-if="props.tab === 'debug'">
<BAlert v-if="!canSubmitFeedback || !stepsJobsSummary" variant="info" show>
<span v-localize>Debug information is not available.</span>
</BAlert>
<WorkflowInvocationFeedback
v-else
:invocation-id="invocation.id"
:steps-jobs-summary="stepsJobsSummary"
:invocation="invocation"
:invocation-messages="uniqueMessages" />
</div>
</div>
</div>
<BAlert v-else-if="errorMessage" variant="danger" show>
{{ errorMessage }}
</BAlert>
<BAlert v-else-if="!invocationLoaded" variant="info" show>
<LoadingSpan message="Loading invocation" />
</BAlert>
<BAlert v-else variant="info" show>
<span v-localize>Invocation not found.</span>
</BAlert>
</template>
<style lang="scss">
// To show the tooltip on the disabled report tab badge
.invocation-report-tab,
.invocation-export-tab {
.nav-link.disabled {
background-color: #e9edf0;
}
}
</style>
<style scoped lang="scss">
.header-collapse-enter-active,
.header-collapse-leave-active {
overflow: hidden;
max-height: 600px;
opacity: 1;
transform: translateY(0);
transition:
max-height 0.3s ease,
opacity 0.25s ease,
transform 0.25s ease;
}
.header-collapse-enter,
.header-collapse-leave-to {
max-height: 0;
opacity: 0;
transform: translateY(-6px);
}
.tab-content-container {
flex: 1;
min-height: 0;
}
.steps-tab-content {
display: flex;
flex-direction: column;
height: 100%;
}
.progress-bars {
// progress bar shrinks to fit divs on either side
flex-grow: 1;
flex-shrink: 1;
.steps-progress,
.jobs-progress {
// truncate text in progress bars
white-space: nowrap;
overflow: hidden;
}
}
</style>