Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions workspaces/bulk-import/.changeset/tiny-ligers-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@red-hat-developer-hub/backstage-plugin-bulk-import': minor
---

Implemented smart polling for import task status in the repository table. Active tasks now poll every 10 seconds for real-time updates, while completed or idle repositories poll every 60 seconds to reduce API load. Polling intervals are aligned to consistent 60-second marks for efficient batching.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import { useRef } from 'react';
import type { MouseEvent } from 'react';

import { Link } from '@backstage/core-components';
Expand Down Expand Up @@ -58,6 +59,7 @@ export const RepositoryTableRow = ({
}) => {
const classes = useStyles();
const bulkImportApi = useApi(bulkImportApiRef);
const startTimeRef = useRef(Date.now());

const { data: value, isLoading: loading } = useQuery(
[
Expand All @@ -80,7 +82,25 @@ export const RepositoryTableRow = ({
{
enabled: !!data.repoUrl,
staleTime: 30000, // Consider data fresh for 30 seconds
refetchInterval: 60000, // Auto-refetch every minute
refetchInterval: queryData => {
const status = (queryData as ImportJobStatus | null)?.status;
const isActiveTask =
status === TaskStatus.Processing ||
status === WorkflowStatus.Active ||
status === WorkflowStatus.Pending;

if (isActiveTask) {
return 10000; // Poll every 10s for active tasks
}

// Calculate time until next 60-second aligned interval
const elapsed = Date.now() - startTimeRef.current;
const intervalMs = 60000;
const remainder = elapsed % intervalMs;
// If exactly at boundary, wait full interval; otherwise wait until next boundary
return remainder === 0 ? intervalMs : intervalMs - remainder;
},
refetchOnWindowFocus: false,
},
);

Expand Down