Calendar/wwwroot/js/workers/SyncManager.d.ts

79 lines
2.1 KiB
TypeScript
Raw Permalink Normal View History

2026-02-03 00:02:25 +01:00
import { IEventBus } from '../types/CalendarTypes';
import { OperationQueue } from '../storage/OperationQueue';
import { IndexedDBService } from '../storage/IndexedDBService';
import { ApiEventRepository } from '../repositories/ApiEventRepository';
/**
* SyncManager - Background sync worker
* Processes operation queue and syncs with API when online
*
* Features:
* - Monitors online/offline status
* - Processes queue with FIFO order
* - Exponential backoff retry logic
* - Updates syncStatus in IndexedDB after successful sync
* - Emits sync events for UI feedback
*/
export declare class SyncManager {
private eventBus;
private queue;
private indexedDB;
private apiRepository;
private isOnline;
private isSyncing;
private syncInterval;
private maxRetries;
private intervalId;
constructor(eventBus: IEventBus, queue: OperationQueue, indexedDB: IndexedDBService, apiRepository: ApiEventRepository);
/**
* Setup online/offline event listeners
*/
private setupNetworkListeners;
/**
* Start background sync worker
*/
startSync(): void;
/**
* Stop background sync worker
*/
stopSync(): void;
/**
* Process operation queue
* Sends pending operations to API
*/
private processQueue;
/**
* Process a single operation
*/
private processOperation;
/**
* Mark event as synced in IndexedDB
*/
private markEventAsSynced;
/**
* Mark event as error in IndexedDB
*/
private markEventAsError;
/**
* Calculate exponential backoff delay
* @param retryCount Current retry count
* @returns Delay in milliseconds
*/
private calculateBackoff;
/**
* Manually trigger sync (for testing or manual sync button)
*/
triggerManualSync(): Promise<void>;
/**
* Get current sync status
*/
getSyncStatus(): {
isOnline: boolean;
isSyncing: boolean;
isRunning: boolean;
};
/**
* Cleanup - stop sync and remove listeners
*/
destroy(): void;
}