# GitSyncWorker

**Kind:** Class

**Source:** [`atloria-monorepo/apps/api/src/git-sync/mirror.worker.ts`](https://github.com/sherkety/atloria/blob/main/atloria-monorepo/apps/api/src/git-sync/mirror.worker.ts#L23)

GitSyncWorker — the single, gated consumer of the 'docs-sync' queue, PLUS the cron sweep
that produces its jobs.

Only spins up where DOCS_REPO_WORKER==='true' (the deployment that mounts the docs-repos
PVC — the mirror reads the substrate via read-only `git show`/`ls-tree` at a pinned sha,
which never touches the shared working tree, so it runs WITHOUT the commit lock and can't
interleave badly with the committer). Api pods enqueue-only.

SWEEP (every minute, worker only — OutboxPoller pattern): any sync with direction
outbound/two-way whose project's ProjectDocsRepo.headCommit has moved past lastSourceSha
gets one coalesced mirror job (deduped by the deterministic jobId). This needs NO hook in
the committer: the reconciler already maintains headCommit on every rebuild.

**Implements:** `OnModuleInit`, `OnModuleDestroy`

## Methods

| Method | Signature | Returns |
|---|---|---|
| `onModuleInit` | `onModuleInit()` | `void` |
| `sweep` | `sweep()` | `Promise<void>` |
| `enqueuePending` | `enqueuePending()` | `Promise<number>` |
| `onModuleDestroy` | `onModuleDestroy()` | `Promise<void>` |

## Where it refuses work

- `GitSyncWorker` stops the work with an early return when `job.data.type !== 'mirror'`.
- `GitSyncWorker` stops the work with an early return when `this.config.get<string>('DOCS_REPO_WORKER') !== 'true'`.

## When something fails

- `GitSyncWorker` handles failure in 1 place: it logs it and continues in all 1.

## Referenced By

- `GitSyncModule` (MODULE_PROVIDES)
