@eleven-am/transcoder
Version:
High-performance HLS transcoding library with hardware acceleration, intelligent client management, and distributed processing support for Node.js
97 lines • 2.92 kB
TypeScript
import { EventEmitter } from 'events';
import { RedisClientType } from 'redis';
import { ISegmentProcessor, SegmentProcessingData, SegmentProcessingResult } from './interfaces';
export interface WorkStealingConfig {
workerId: string;
stealThreshold: number;
stealCheckInterval: number;
maxStealsPerCheck: number;
}
/**
* Extends distributed processing with work stealing capability
* Monitors for stuck segments and steals them from unresponsive workers
*/
export declare class WorkStealingProcessor extends EventEmitter implements ISegmentProcessor {
private readonly baseProcessor;
private stealCheckTimer;
private readonly config;
private isDisposed;
private readonly MAX_STEAL_ATTEMPTS;
private readonly activeStealAttempts;
private consecutiveFailures;
private readonly maxFailures;
private readonly failureBackoff;
constructor(redis: RedisClientType, config?: Partial<WorkStealingConfig>);
/**
* Process a segment with work stealing support
*/
processSegment(data: SegmentProcessingData): Promise<SegmentProcessingResult>;
/**
* Check if healthy with work stealing capability
*/
isHealthy(): Promise<boolean>;
/**
* Get processing mode
*/
getMode(): string;
/**
* Start monitoring for stuck segments
*/
private startWorkStealingMonitor;
private limitSegmentsToSteal;
private emitDetectionEvent;
private countResults;
private emitCompletionEvent;
private handleFailure;
private shouldTripCircuitBreaker;
private tripCircuitBreaker;
private resetFailureCount;
private findStuckSegmentsTask;
private attemptStealSegmentTask;
private attemptStealSegments;
/**
* Check for stuck segments and attempt to steal them
*/
private checkAndStealWork;
private calculateClaimAge;
private isSegmentStuck;
private isNotBeingStolen;
private parseSegmentData;
private filterStuckSegments;
private getClaimedSegmentsTask;
/**
* Find segments that appear to be stuck
*/
private findStuckSegments;
private markSegmentAsBeingStolen;
private unmarkSegmentAsBeingStolen;
private getOriginalSegmentKey;
private emitWorkStolenEvent;
private forceClaimSegmentTask;
private processSegmentTask;
/**
* Attempt to steal a specific segment
*/
private attemptStealSegment;
/**
* Get unique key for a segment
*/
private getSegmentKey;
/**
* Dispose and clean up
*/
dispose(): Promise<void>;
/**
* Get work stealing metrics
*/
getMetrics(): {
mode: string;
workerId: string;
activeStealAttempts: number;
stealThreshold: number;
checkInterval: number;
};
private evictOldestStealAttempt;
private clearAllStealAttempts;
}
//# sourceMappingURL=workStealingProcessor.d.ts.map