mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-22 11:20:15 +01:00
refactor: Enhance GenerationJobManager with improved subscriber handling
- Updated RuntimeJobState to include allSubscribersLeftHandlers for managing client disconnections without affecting subscriber count. - Refined createJob and subscribe methods to ensure generation starts only when the first real client connects. - Added detailed documentation for methods and properties to clarify the synchronization of job generation with client readiness. - Improved logging for subscriber checks and event handling to facilitate debugging and monitoring.
This commit is contained in:
parent
3a0c1476da
commit
bf9f2a3082
3 changed files with 107 additions and 21 deletions
|
|
@ -43,6 +43,10 @@ export class InMemoryEventTransport implements IEventTransport {
|
|||
state.emitter.on('done', doneHandler);
|
||||
state.emitter.on('error', errorHandler);
|
||||
|
||||
logger.debug(
|
||||
`[InMemoryEventTransport] subscribe ${streamId}: listeners=${state.emitter.listenerCount('chunk')}`,
|
||||
);
|
||||
|
||||
return {
|
||||
unsubscribe: () => {
|
||||
const currentState = this.streams.get(streamId);
|
||||
|
|
@ -90,7 +94,9 @@ export class InMemoryEventTransport implements IEventTransport {
|
|||
*/
|
||||
isFirstSubscriber(streamId: string): boolean {
|
||||
const state = this.streams.get(streamId);
|
||||
return state?.emitter.listenerCount('chunk') === 1;
|
||||
const count = state?.emitter.listenerCount('chunk') ?? 0;
|
||||
logger.debug(`[InMemoryEventTransport] isFirstSubscriber ${streamId}: count=${count}`);
|
||||
return count === 1;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue