Skip to content

Commit

Permalink
stop polling when reconcile error
Browse files Browse the repository at this point in the history
  • Loading branch information
lovincyrus committed Dec 10, 2024
1 parent be83b38 commit ab4b6ea
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions web-admin/src/features/projects/status/ProjectResources.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
let maxRefetchAttempts = 60; // 30 seconds maximum
let refetchAttempts = 0;
let pollInterval: ReturnType<typeof setInterval> | null = null;
let individualRefresh = false;
$: allResources = createRuntimeServiceListResources(
$runtime.instanceId,
Expand Down Expand Up @@ -54,13 +55,28 @@
),
);
$: hasReconcileError = Boolean(
$allResources?.data?.some((resource) => !!resource.meta.reconcileError),
);
function startPolling() {
stopPolling(); // Clear any existing interval
stopPolling();
refetchAttempts = 0;
pollInterval = setInterval(() => {
refetchAttempts++;
// Check for reconcile error during polling
if (individualRefresh && hasReconcileError) {
stopPolling();
// Refetch resources for latest reconcile status
void $allResources.refetch();
individualRefresh = false;
return;
}
if (refetchAttempts >= maxRefetchAttempts) {
stopPolling();
return;
Expand Down Expand Up @@ -97,7 +113,8 @@
);
}
function triggerRefresh() {
function refreshResource() {
individualRefresh = true;
startPolling();
void $allResources.refetch();
}
Expand Down Expand Up @@ -132,7 +149,10 @@
Error loading resources: {$allResources.error?.message}
</div>
{:else if $allResources.data}
<ProjectResourcesTable data={$allResources.data} {triggerRefresh} />
<ProjectResourcesTable
data={$allResources.data}
triggerRefresh={refreshResource}
/>
{/if}
</section>

Expand Down

0 comments on commit ab4b6ea

Please sign in to comment.