MCPcopy
hub / github.com/stravu/crystal / constructor

Method constructor

main/src/services/taskQueue.ts:71–146  ·  view source on GitHub ↗
(private options: TaskQueueOptions)

Source from the content-addressed store, hash-verified

69 private useSimpleQueue: boolean;
70
71 constructor(private options: TaskQueueOptions) {
72 console.log('[TaskQueue] Initializing task queue...');
73
74 // Check if we're in Electron without Redis
75 this.useSimpleQueue = !process.env.REDIS_URL && typeof process.versions.electron !== 'undefined';
76
77 // Determine concurrency based on platform
78 // Linux has stricter PTY and file descriptor limits, so we reduce concurrency
79 const isLinux = os.platform() === 'linux';
80 const sessionConcurrency = isLinux ? 1 : 5;
81
82 console.log(`[TaskQueue] Platform: ${os.platform()}, Session concurrency: ${sessionConcurrency}`);
83
84 if (this.useSimpleQueue) {
85 console.log('[TaskQueue] Using SimpleQueue for Electron environment');
86
87 this.sessionQueue = new SimpleQueue<CreateSessionJob>('session-creation', sessionConcurrency);
88 this.inputQueue = new SimpleQueue<SendInputJob>('session-input', 10);
89 this.continueQueue = new SimpleQueue<ContinueSessionJob>('session-continue', 10);
90 } else {
91 // Use Bull with Redis
92 const redisOptions = process.env.REDIS_URL ? {
93 redis: process.env.REDIS_URL
94 } : undefined;
95
96 console.log('[TaskQueue] Using Bull with Redis:', process.env.REDIS_URL || 'default');
97
98 this.sessionQueue = new Bull('session-creation', redisOptions || {
99 defaultJobOptions: {
100 removeOnComplete: true,
101 removeOnFail: false
102 }
103 });
104
105 this.inputQueue = new Bull('session-input', redisOptions || {
106 defaultJobOptions: {
107 removeOnComplete: true,
108 removeOnFail: false
109 }
110 });
111
112 this.continueQueue = new Bull('session-continue', redisOptions || {
113 defaultJobOptions: {
114 removeOnComplete: true,
115 removeOnFail: false
116 }
117 });
118 }
119
120 // Add event handlers for debugging
121 this.sessionQueue.on('active', (...args: unknown[]) => {
122 const job = args[0] as { id: string | number };
123 // Job active tracking removed - verbose debug logging
124 });
125
126 this.sessionQueue.on('completed', (...args: unknown[]) => {
127 const job = args[0] as { id: string | number };
128 const result = args[1];

Callers

nothing calls this directly

Calls 4

setupProcessorsMethod · 0.95
onMethod · 0.80
errorMethod · 0.80
logMethod · 0.45

Tested by

no test coverage detected