(sourceId: string, sessionIds: string[], maxAttempts = 24, intervalMs = 5000)
| 411 | } |
| 412 | |
| 413 | function pollDataSourceUpdates(sourceId: string, sessionIds: string[], maxAttempts = 24, intervalMs = 5000) { |
| 414 | let attempt = 0 |
| 415 | const timer = setInterval(async () => { |
| 416 | attempt++ |
| 417 | await Promise.all([fetchDataSources(), fetchSyncProgress()]) |
| 418 | const ds = dataSources.value.find((s) => s.id === sourceId) |
| 419 | const pending = sessionIds.filter((id) => { |
| 420 | const sess = ds?.sessions.find((s) => s.id === id) |
| 421 | return sess && sess.lastStatus === 'idle' |
| 422 | }) |
| 423 | if (pending.length === 0 || attempt >= maxAttempts) { |
| 424 | for (const id of sessionIds) { |
| 425 | pullingIds.value.delete(id) |
| 426 | syncProgress.value.delete(id) |
| 427 | } |
| 428 | pullingIds.value = new Set(pullingIds.value) |
| 429 | syncProgress.value = new Map(syncProgress.value) |
| 430 | clearInterval(timer) |
| 431 | } |
| 432 | }, intervalMs) |
| 433 | } |
| 434 | |
| 435 | async function fetchSyncProgress() { |
| 436 | if (!isWebMode.value) return |
no test coverage detected