-
Notifications
You must be signed in to change notification settings - Fork 146
Expand file tree
/
Copy pathactivity-execution-retry-schedule.svelte
More file actions
186 lines (170 loc) · 5.58 KB
/
activity-execution-retry-schedule.svelte
File metadata and controls
186 lines (170 loc) · 5.58 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
<script lang="ts">
import Timestamp from '$lib/components/timestamp.svelte';
import Card from '$lib/holocene/card.svelte';
import { type StandaloneActivity } from '$lib/pages/standalone-activity.svelte';
import { formatSecondsAbbreviated } from '$lib/utilities/format-time';
import { fromSeconds } from '$lib/utilities/to-duration';
import DetailListColumn from '../detail-list/detail-list-column.svelte';
import DetailListLabel from '../detail-list/detail-list-label.svelte';
import DetailListTextValue from '../detail-list/detail-list-text-value.svelte';
import DetailList from '../detail-list/detail-list.svelte';
interface Props {
activity: StandaloneActivity;
}
let { activity }: Props = $props();
let graphWidth = $state(500);
let graphHeight = $state(240);
const BAR_CHART_PADDING_LEFT = 48;
const BAR_CHART_PADDING_BOTTOM = 48;
const BAR_CHART_PADDING_TOP = 32;
const BAR_CHART_PADDING_RIGHT = 0;
const chartMaxY = $derived(activity.maximumInterval ?? 1);
const chartInnerWidth = $derived(
graphWidth - BAR_CHART_PADDING_LEFT - BAR_CHART_PADDING_RIGHT,
);
const chartInnerHeight = $derived(
graphHeight - BAR_CHART_PADDING_BOTTOM - BAR_CHART_PADDING_TOP,
);
const barWidth = $derived(
activity.schedule.length > 0
? chartInnerWidth / activity.schedule.length - 2
: 20,
);
function barHeight(waitSeconds: number): number {
if (chartMaxY === 0) return 0;
return (waitSeconds / chartMaxY) * chartInnerHeight;
}
function barX(index: number): number {
if (activity.schedule.length === 0) return 0;
return (
BAR_CHART_PADDING_LEFT +
index * (chartInnerWidth / activity.schedule.length) +
1
);
}
function barY(waitSeconds: number): number {
return BAR_CHART_PADDING_TOP + chartInnerHeight - barHeight(waitSeconds);
}
const yAxisLabels = $derived.by(() => {
const steps = 4;
const labels = [];
for (let i = 0; i <= steps; i++) {
const val = (chartMaxY / steps) * i;
labels.push({
val: formatSecondsAbbreviated(Math.round(val)),
y:
BAR_CHART_PADDING_TOP +
chartInnerHeight -
(val / chartMaxY) * chartInnerHeight,
});
}
return labels;
});
</script>
<Card class="flex flex-col gap-4 pt-5">
<div>
<h5 class="text-xs font-semibold uppercase tracking-wide">
Retry Schedule
</h5>
{#if !activity.maximumAttempts}
<span class="text-xs text-secondary"
>(only showing the first 50 attempts)</span
>
{/if}
</div>
<DetailList aria-label="Retry Policy" rowCount={2}>
<DetailListColumn>
<DetailListLabel>Initial Interval</DetailListLabel>
<DetailListTextValue text={fromSeconds(activity.initialInterval)} />
<DetailListLabel>Maximum Interval</DetailListLabel>
<DetailListTextValue text={fromSeconds(activity.maximumInterval)} />
</DetailListColumn>
<DetailListColumn>
<DetailListLabel>Backoff Coefficient</DetailListLabel>
<DetailListTextValue text={String(activity.backoffCoefficient)} />
<DetailListLabel>Maximum Attempts</DetailListLabel>
<DetailListTextValue
text={activity.maximumAttempts ? String(activity.maximumAttempts) : '-'}
/>
</DetailListColumn>
</DetailList>
<div
bind:clientWidth={graphWidth}
bind:clientHeight={graphHeight}
class="overflow-auto"
>
<svg
width={graphWidth}
height={graphHeight}
viewBox="0 0 {graphWidth} {graphHeight}"
>
{#each yAxisLabels as label (label.val)}
<line
x1={BAR_CHART_PADDING_LEFT}
y1={label.y}
x2={graphWidth - BAR_CHART_PADDING_RIGHT}
y2={label.y}
/>
<text
x={BAR_CHART_PADDING_LEFT - 4}
y={label.y + 4}
text-anchor="end"
font-size="9"
fill="currentColor"
opacity="0.5">{label.val}</text
>
{/each}
{#each activity.schedule as entry, i (entry.attempt)}
{@const isCurrentAttempt = entry.attempt === activity.currentAttempt}
<rect
x={barX(i)}
y={barY(entry.waitSeconds)}
width={barWidth}
height={barHeight(entry.waitSeconds)}
class={isCurrentAttempt ? 'fill-brand' : 'fill-subtle'}
rx="2"
/>
{#if i % 2 === 0}
<text
x={barX(i) + barWidth / 2}
y={graphHeight - BAR_CHART_PADDING_BOTTOM + 14}
text-anchor="middle"
font-size="9"
fill="currentColor"
opacity="0.6">{entry.attempt}</text
>
{/if}
{/each}
<text
x={graphWidth / 2}
y={graphHeight - 8}
text-anchor="middle"
fill="currentColor"
opacity="0.6"
font-size="10">attempt</text
>
</svg>
</div>
<div
class="mt-auto flex items-center justify-between border-t border-subtle pt-2"
>
<div class=" flex flex-col gap-0.5">
<span class="text-xs font-semibold uppercase tracking-wide">Started</span>
<span class="text-sm text-secondary">
<Timestamp dateTime={activity.scheduleTime} />
</span>
</div>
<div class=" flex flex-col gap-0.5 text-right">
<span class="text-xs font-semibold uppercase tracking-wide"
>{activity.running ? 'Stops' : 'Stopped'}</span
>
<span class="text-sm text-secondary">
{#if activity.running && activity.deadlineTime}
<Timestamp dateTime={activity.deadlineTime} />
{:else if !activity.running}
<Timestamp dateTime={activity.closeTime} />
{/if}
</span>
</div>
</div>
</Card>