-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor: Extract common worker logic to eliminate ~500 lines of duplication #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feature/quadrant-lr-sw
Are you sure you want to change the base?
Conversation
- Created shared/worker-utils.ts with createUnifiedWorkerHandler factory - Extracted logWorkerMetrics function to shared utility - Extracted HandlerResult interface to shared utility - Updated SR, SW, LR, and LW workers to use shared utility - Reduced code duplication by ~500 lines - Added performance metrics to LW worker (previously missing) Co-authored-by: llama90 <6668548+llama90@users.noreply.github.com>
- Remove HandlerResult | void union type from WorkerConfig - All handlers now required to return HandlerResult - Updated build handler to return HandlerResult with syncResponseMs - Removed fragile type check for handlerResult (always defined now) - Improved type consistency across all handlers Co-authored-by: llama90 <6668548+llama90@users.noreply.github.com>
- Added detailed JSDoc explaining the function's purpose - Documented use cases (E2E latency, queue wait time, etc.) - Added parameter documentation - Improved code maintainability and discoverability Co-authored-by: llama90 <6668548+llama90@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@copilot Please refactor this code into smaller functions that are easier to test. |
Split createUnifiedWorkerHandler into focused, single-responsibility functions: - parseWorkerMessage: Extracts message parsing logic - createMessageLogger: Handles logger creation with correlation context - getCommandHandler: Validates and retrieves command handlers - calculatePerformanceMetrics: Computes timing metrics - processRecord: Orchestrates single record processing Benefits: - Each function has a clear, testable purpose - Easier to unit test individual components - Maintains exact same behavior and async boundaries - No changes to external function signatures - More maintainable and easier to understand Co-authored-by: llama90 <6668548+llama90@users.noreply.github.com>
I've refactored the code into smaller, focused functions. The main handler is now broken down into: New functions (all with single responsibilities):
Result:
The refactor maintains pragmatism - each extracted function has a clear purpose without over-abstracting. Commit: 32b6978 |
src/shared/worker-utils.tswith common handler logiclogWorkerMetricsfunction to shared utilityHandlerResultinterface to shared typescreateUnifiedWorkerHandlerfactory function that accepts configuration✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.