Skip to content

Commit

Permalink
Merge pull request #2272 from flanksource/allow-refetch-in-the-backgr…
Browse files Browse the repository at this point in the history
…ound

fix: enable playbook runs refresh when tab is unfocussed
  • Loading branch information
flankbot authored Sep 10, 2024
2 parents e5d799c + 67191bf commit 73d04fb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export default function PlaybookRunActionFetch({
enabled: !!playbookRunActionId,
staleTime: 0,
cacheTime: 0,
// We want to refetch the playbook run every 5 seconds when the page is in
// the background.
refetchIntervalInBackground: true,
refetchInterval: (data) => {
if (data?.status !== "completed" && data?.status !== "failed") {
return 1000;
Expand Down
9 changes: 6 additions & 3 deletions src/pages/playbooks/PlaybookRunsDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,17 @@ export default function PlaybookRunsDetailsPage() {
enabled: !!id,
staleTime: 0,
cacheTime: 0,
// We want to refetch the playbook run every 5 seconds when the page is in
// the background.
refetchIntervalInBackground: true,
// When the playbook run is running or pending, we want to refetch every 5
// seconds to get the latest status. Otherwise, we don't want to refetch at
// all.
refetchInterval: (playbookRun) => {
if (
playbookRun?.status === "running" ||
playbookRun?.status === "waiting" ||
playbookRun?.status === "pending"
playbookRun?.status !== "completed" &&
playbookRun?.status !== "failed" &&
playbookRun?.status !== "cancelled"
) {
return 2000;
}
Expand Down

0 comments on commit 73d04fb

Please sign in to comment.