Refactor hook timeout settings to use centralized constants
- Introduced a new module `hook-constants.ts` to define timeout constants for various hooks. - Updated `cleanup-hook.ts`, `context-hook.ts`, `save-hook.ts`, and `summary-hook.ts` to utilize the new `HOOK_TIMEOUTS.DEFAULT` for fetch timeouts instead of hardcoded values. - Adjusted worker utility timeouts in `worker-utils.ts` to use constants from `hook-constants.ts`, improving maintainability and consistency across the codebase.
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
export const HOOK_TIMEOUTS = {
|
||||
DEFAULT: 5000, // Standard HTTP timeout (up from 2000ms)
|
||||
HEALTH_CHECK: 1000, // Worker health check (up from 500ms)
|
||||
WORKER_STARTUP_WAIT: 1000,
|
||||
WORKER_STARTUP_RETRIES: 15,
|
||||
WINDOWS_MULTIPLIER: 1.5 // Platform-specific adjustment
|
||||
} as const;
|
||||
|
||||
export function getTimeout(baseTimeout: number): number {
|
||||
return process.platform === 'win32'
|
||||
? Math.round(baseTimeout * HOOK_TIMEOUTS.WINDOWS_MULTIPLIER)
|
||||
: baseTimeout;
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import { homedir } from "os";
|
||||
import { spawnSync } from "child_process";
|
||||
import { SettingsDefaultsManager } from "../services/worker/settings/SettingsDefaultsManager.js";
|
||||
import { logger } from "../utils/logger.js";
|
||||
import { HOOK_TIMEOUTS, getTimeout } from "./hook-constants.js";
|
||||
|
||||
// CRITICAL: Always use marketplace directory for PM2/ecosystem
|
||||
// This ensures cross-platform compatibility and avoids cache directory confusion
|
||||
@@ -11,9 +12,9 @@ const MARKETPLACE_ROOT = path.join(homedir(), '.claude', 'plugins', 'marketplace
|
||||
|
||||
// Named constants for health checks
|
||||
// Windows needs longer timeouts due to startup overhead
|
||||
const HEALTH_CHECK_TIMEOUT_MS = 500;
|
||||
const WORKER_STARTUP_WAIT_MS = 1000;
|
||||
const WORKER_STARTUP_RETRIES = 15;
|
||||
const HEALTH_CHECK_TIMEOUT_MS = getTimeout(HOOK_TIMEOUTS.HEALTH_CHECK);
|
||||
const WORKER_STARTUP_WAIT_MS = HOOK_TIMEOUTS.WORKER_STARTUP_WAIT;
|
||||
const WORKER_STARTUP_RETRIES = HOOK_TIMEOUTS.WORKER_STARTUP_RETRIES;
|
||||
|
||||
/**
|
||||
* Get the worker port number
|
||||
|
||||
Reference in New Issue
Block a user