Skip to content

feat(sync-engine): introduce pluggable SyncHandler interface in SyncManager #37

@rohansaini-02

Description

@rohansaini-02

Problem

In poc-sync-engine/src/SyncManager.ts, processing queue items depends on a hardcoded mock API call:

private async mockFrappeApiCall(job: SyncJob): Promise<void> {
  // Hardcoded simulation
}

This tightly couples queue orchestration with a mock transport implementation, making it difficult to integrate real HTTP clients or reuse SyncManager across environments.

Proposed Solution

  1. Define a pluggable SyncHandler interface that accepts a SyncJob and processes it:
    export interface SyncHandler {
      handle(job: SyncJob): Promise<void>;
    }
    Note: The initial interface can remain minimal, while still allowing future implementations to extend sync result handling or retry behavior without coupling execution logic directly to SyncManager.
  2. Modify the SyncManager constructor to accept this interface:
    export class SyncManager {
      private queue: SyncQueue;
      private handler: SyncHandler;
      ...
      constructor(queue: SyncQueue, handler: SyncHandler) {
        this.queue = queue;
        this.handler = handler;
      }
    }
  3. Delegate sync execution in drainQueue() to this.handler.handle(job) instead of the private mock helper.
  4. Error propagation and retry behavior should remain controlled by SyncManager, while execution details remain delegated to the injected handler.

Acceptance Criteria

  • SyncManager has no hardcoded mock API client call inside.
  • SyncManager supports interchangeable handler implementations (e.g., mock or HTTP-backed handlers).
  • Unit tests are refactored to inject a mock SyncHandler instance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions