Refactor: Decompose async_worker.py into smaller modules #3868

Open
opened 2026-04-06 07:02:57 +00:00 by freemo · 0 comments
Owner

The src/cleveragents/application/services/async_worker.py file has been identified as a violation of the Single Responsibility Principle and the 500-line limit guideline.

Issues:

  1. Mixed Concerns: The file contains several distinct classes that should be in separate modules:
    • CancellationToken: A general-purpose utility.
    • WorkerHealthReport: A data model.
    • AsyncWorkerConfig: A data model.
    • InMemoryJobStore: An in-memory repository implementation.
    • AsyncWorker: The main service class.
  2. File Length: The file is over 650 lines long, which makes it difficult to read and maintain.

Recommendation:

Refactor the async_worker.py file by splitting it into smaller, more focused modules:

  • Move CancellationToken to a shared or core module.
  • Move WorkerHealthReport and AsyncWorkerConfig to src/cleveragents/domain/models.
  • Move InMemoryJobStore to the src/cleveragents/infrastructure layer.
  • Keep the AsyncWorker class in src/cleveragents/application/services, but in its own file.

This refactoring will improve the modularity, maintainability, and testability of the async worker functionality.


Automated by CleverAgents Bot
Supervisor: Architecture Guard | Agent: ca-architecture-guard

The `src/cleveragents/application/services/async_worker.py` file has been identified as a violation of the Single Responsibility Principle and the 500-line limit guideline. **Issues:** 1. **Mixed Concerns:** The file contains several distinct classes that should be in separate modules: * `CancellationToken`: A general-purpose utility. * `WorkerHealthReport`: A data model. * `AsyncWorkerConfig`: A data model. * `InMemoryJobStore`: An in-memory repository implementation. * `AsyncWorker`: The main service class. 2. **File Length:** The file is over 650 lines long, which makes it difficult to read and maintain. **Recommendation:** Refactor the `async_worker.py` file by splitting it into smaller, more focused modules: * Move `CancellationToken` to a `shared` or `core` module. * Move `WorkerHealthReport` and `AsyncWorkerConfig` to `src/cleveragents/domain/models`. * Move `InMemoryJobStore` to the `src/cleveragents/infrastructure` layer. * Keep the `AsyncWorker` class in `src/cleveragents/application/services`, but in its own file. This refactoring will improve the modularity, maintainability, and testability of the async worker functionality. --- **Automated by CleverAgents Bot** Supervisor: Architecture Guard | Agent: ca-architecture-guard
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core#3868
No description provided.