()
| 948 | } |
| 949 | |
| 950 | async function processQueue() { |
| 951 | if (processing || queue.length === 0) { |
| 952 | debugAutoDataSync('skip queue processing', { |
| 953 | processing, |
| 954 | pendingCount: queue.length, |
| 955 | }) |
| 956 | return |
| 957 | } |
| 958 | |
| 959 | if (!await isAutoDataSyncEnabled()) { |
| 960 | queue = [] |
| 961 | debugAutoDataSync('clear queue because auto data sync is disabled') |
| 962 | updateState({ |
| 963 | isSyncing: false, |
| 964 | phase: 'idle', |
| 965 | currentDomain: null, |
| 966 | status: 'idle', |
| 967 | lastError: null, |
| 968 | }) |
| 969 | return |
| 970 | } |
| 971 | |
| 972 | if (!await isAutoDataSyncProviderConfigured()) { |
| 973 | queue = [] |
| 974 | debugAutoDataSync('clear queue because provider is not configured') |
| 975 | updateState({ |
| 976 | isSyncing: false, |
| 977 | phase: 'waiting_provider', |
| 978 | currentDomain: null, |
| 979 | syncMode: null, |
| 980 | status: 'waiting_provider', |
| 981 | lastError: null, |
| 982 | }) |
| 983 | return |
| 984 | } |
| 985 | |
| 986 | processing = true |
| 987 | const uploadedDomains = new Set<AutoDataSyncDomain>() |
| 988 | debugAutoDataSync('queue processing started', { pendingCount: queue.length }) |
| 989 | |
| 990 | while (queue.length > 0) { |
| 991 | const task = queue.shift() |
| 992 | if (!task) { |
| 993 | continue |
| 994 | } |
| 995 | |
| 996 | debugAutoDataSync('task started', { |
| 997 | id: task.id, |
| 998 | seq: task.seq, |
| 999 | domain: task.domain, |
| 1000 | reason: task.reason, |
| 1001 | mode: task.mode, |
| 1002 | retryCount: task.retryCount, |
| 1003 | remainingCount: queue.length, |
| 1004 | }) |
| 1005 | const taskStartedAt = Date.now() |
| 1006 | |
| 1007 | try { |
no test coverage detected