refactor: Complete rewrite of worker-utils.ts and cleanup of worker-service.ts
- Removed fragile PM2 string parsing and replaced with direct PM2 restart logic. - Eliminated silent error handling in worker-utils.ts for better error visibility. - Extracted duplicated session auto-creation logic into a new helper method getOrCreateSession() in worker-service.ts. - Centralized configuration values and replaced magic numbers with named constants. - Updated health check logic to ensure worker is restarted if unhealthy. - Removed unnecessary getWorkerPort() wrapper function. - Improved overall code quality and maintainability by applying DRY and YAGNI principles.
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
|
||||
import { stdin } from 'process';
|
||||
import { SessionStore } from '../services/sqlite/SessionStore.js';
|
||||
import { getWorkerPort } from '../shared/worker-utils.js';
|
||||
|
||||
export interface SessionEndInput {
|
||||
session_id: string;
|
||||
@@ -71,7 +72,7 @@ async function cleanupHook(input?: SessionEndInput): Promise<void> {
|
||||
|
||||
// Tell worker to stop spinner
|
||||
try {
|
||||
const workerPort = session.worker_port || 37777;
|
||||
const workerPort = session.worker_port || getWorkerPort();
|
||||
await fetch(`http://127.0.0.1:${workerPort}/sessions/${session.id}/complete`, {
|
||||
method: 'POST',
|
||||
signal: AbortSignal.timeout(1000)
|
||||
|
||||
Reference in New Issue
Block a user