UNPKG

@casoon/auditmysite

Version:

Professional website analysis suite with robust accessibility testing, Core Web Vitals performance monitoring, SEO analysis, and content optimization insights. Features isolated browser contexts, retry mechanisms, and comprehensive API endpoints for profe

230 lines 6.88 kB
"use strict"; /** * 🔧 Unified Queue System * * Main class that provides a unified interface for all queue types. * Uses the Adapter Pattern to provide consistent API regardless of implementation. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.UnifiedQueue = void 0; const queue_factory_1 = require("./queue-factory"); class UnifiedQueue { constructor(type = 'parallel', config = {}, callbacks) { // Validate configuration const validation = queue_factory_1.QueueFactory.validateConfig(config); if (!validation.valid) { throw new Error(`Invalid queue configuration: ${validation.errors.join(', ')}`); } this.type = type; this.config = { ...queue_factory_1.QueueFactory.getDefaultConfig(type), ...config }; this.adapter = queue_factory_1.QueueFactory.create(type, this.config, callbacks); } /** * Create queue optimized for accessibility testing */ static forAccessibilityTesting(type = 'parallel', customConfig = {}, callbacks) { const adapter = queue_factory_1.QueueFactory.createForAccessibilityTesting(type, customConfig, callbacks); const instance = Object.create(UnifiedQueue.prototype); instance.adapter = adapter; instance.type = type; instance.config = adapter.getConfiguration(); return instance; } /** * Add items to the queue */ enqueue(data, options) { return this.adapter.enqueue(data, options); } /** * Add a single item to the queue */ enqueueOne(data, priority) { const ids = this.adapter.enqueue([data], { priority }); return ids[0]; } /** * Process all items in the queue */ async process(processor) { return this.adapter.process(processor); } /** * Get queue statistics */ getStatistics() { return this.adapter.getStatistics(); } /** * Pause queue processing */ pause() { this.adapter.pause(); } /** * Resume queue processing */ resume() { this.adapter.resume(); } /** * Clear all items from the queue */ clear() { this.adapter.clear(); } /** * Update queue configuration */ configure(config) { // Validate new configuration const mergedConfig = { ...this.config, ...config }; const validation = queue_factory_1.QueueFactory.validateConfig(mergedConfig); if (!validation.valid) { throw new Error(`Invalid queue configuration: ${validation.errors.join(', ')}`); } this.config = mergedConfig; this.adapter.configure(config); } /** * Get current configuration */ getConfiguration() { return this.adapter.getConfiguration(); } /** * Get queue type */ getType() { return this.type; } /** * Check if queue is currently processing */ isActive() { return this.adapter.isActive(); } /** * Get all queue items */ getItems() { return this.adapter.getItems(); } /** * Get items by status */ getItemsByStatus(status) { return this.adapter.getItemsByStatus(status); } /** * Get queue size */ size() { return this.getItems().length; } /** * Check if queue is empty */ isEmpty() { return this.size() === 0; } /** * Get performance metrics */ getPerformanceMetrics() { const stats = this.getStatistics(); return { throughput: stats.throughput, averageDuration: stats.averageDuration, efficiency: stats.total > 0 ? (stats.completed / stats.total) * 100 : 0, errorRate: stats.total > 0 ? (stats.failed / stats.total) * 100 : 0, memoryUsage: stats.memoryUsage, cpuUsage: stats.cpuUsage }; } /** * Export queue state for debugging */ exportState() { const stats = this.getStatistics(); const items = this.getItems(); return { type: this.type, config: this.config, statistics: stats, items: items.map(item => ({ id: item.id, status: item.status, priority: item.priority, attempts: item.attempts, duration: item.duration, error: item.error })), timestamp: new Date().toISOString() }; } /** * Clean up queue resources */ async cleanup() { // Clear all items this.clear(); // If the adapter has a cleanup method, call it if (typeof this.adapter.cleanup === 'function') { await this.adapter.cleanup(); } } /** * Create progress reporter that updates at regular intervals */ createProgressReporter(interval = 2000) { const timer = setInterval(() => { const stats = this.getStatistics(); console.log(`🚀 Queue Progress: ${stats.progress.toFixed(1)}% (${stats.completed}/${stats.total}) | Workers: ${stats.activeWorkers} | ETA: ${Math.round(stats.estimatedTimeRemaining / 1000)}s`); }, interval); return () => clearInterval(timer); } /** * Wait for queue to complete processing */ async waitForCompletion(checkInterval = 500) { return new Promise((resolve) => { const check = () => { if (!this.isActive() && this.getItemsByStatus('pending').length === 0) { resolve(); } else { setTimeout(check, checkInterval); } }; check(); }); } /** * Process items with automatic retry and progress reporting */ async processWithProgress(items, processor, options) { // Add items to queue this.enqueue(items); // Setup progress reporter let stopProgress; if (options?.showProgress !== false) { stopProgress = this.createProgressReporter(options?.progressInterval); } try { // Process queue const result = await this.process(processor); // Final progress report if (options?.showProgress !== false) { const stats = result.statistics; console.log(`✅ Queue completed: ${stats.completed}/${stats.total} items | ${stats.failed} failed | Duration: ${Math.round(result.duration / 1000)}s`); } return result; } finally { stopProgress?.(); } } } exports.UnifiedQueue = UnifiedQueue; //# sourceMappingURL=unified-queue.js.map