Skip to content

Commit bf43c75

Browse files
authored
Merge pull request #17 from MapColonies/MAPCO-9803/implement-cleaner-worker-skeleton
feat: implement cleaner worker skeleton with error handling, validation, and strategy pattern (MAPCO-9803)
2 parents a0c8cc9 + 1ed8e3f commit bf43c75

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+6833
-2639
lines changed

.github/copilot-instructions.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
**Cleaner** is a TypeScript-based worker service built on the MapColonies Jobnik SDK framework. It is a distributed task processing worker that handles cleanup operations as part of the raster processing pipeline.
66

7-
This project is based on the `jobnik-worker-boilerplate` template and follows the MapColonies ecosystem conventions for observability, configuration, and deployment.
7+
This project is based on the `cleaner` template and follows the MapColonies ecosystem conventions for observability, configuration, and deployment.
88

99
## Quick Reference
1010

@@ -55,15 +55,22 @@ npm run lint:fix # Auto-fix linting issues
5555

5656
## Important Notes for AI Agents
5757

58-
1. **Remove Demo Code**: The `logistics/` folder and `seeder.ts` are examples. Replace with actual cleaner implementation.
58+
1. **Incremental Commits & PRs**: Always implement changes in small commits grouped into reviewable PRs. After implementing each part:
59+
- Stage files with `git add`
60+
- Stop and wait for user confirmation before committing
61+
- Only commit after explicit user approval
62+
- Use conventional commits: `<type>(<scope>): <description>`
63+
- When enough commits are accumulated (3-5 related commits), STOP and tell user to create PR before continuing
5964

60-
2. **Package Metadata**: Update `package.json` name from `jobnik-worker-boilerplate` to `cleaner`.
65+
2. **Remove Demo Code**: The `logistics/` folder and `seeder.ts` are examples. Replace with actual cleaner implementation.
6166

62-
3. **Type Safety**: Define job/stage types in `src/cleaner/types.ts` and update `worker.ts` with correct generic parameters.
67+
3. **Package Metadata**: Update `package.json` name from `cleaner` to `cleaner`.
6368

64-
4. **Path Aliases**: Use `@common/` for imports from `src/common/`.
69+
4. **Type Safety**: Define job/stage types in `src/cleaner/types.ts` and update `worker.ts` with correct generic parameters.
6570

66-
5. **Endpoints**: `/metrics` (Prometheus), `/liveness` (health check).
71+
5. **Path Aliases**: Use `@common/` for imports from `src/common/`.
72+
73+
6. **Endpoints**: `/metrics` (Prometheus), `/liveness` (health check).
6774

6875
## Common Tasks
6976

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ typings/
7777
.env.test
7878
config.json
7979

80+
# Local configuration overrides
81+
config/local.json
82+
helm/local.yaml
83+
84+
# Local documentation (can be regenerated)
85+
ai-docs/implementation-plan.md
86+
8087
# parcel-bundler cache (https://parceljs.org/)
8188
.cache
8289

AGENTS.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
**Cleaner** is a TypeScript-based worker service built on the MapColonies Jobnik SDK framework. It is a distributed task processing worker that handles cleanup operations as part of the raster processing pipeline.
66

7-
This project is based on the `jobnik-worker-boilerplate` template and follows the MapColonies ecosystem conventions for observability, configuration, and deployment.
7+
This project is based on the `cleaner` template and follows the MapColonies ecosystem conventions for observability, configuration, and deployment.
88

99
## Quick Reference
1010

@@ -55,15 +55,22 @@ npm run lint:fix # Auto-fix linting issues
5555

5656
## Important Notes for AI Agents
5757

58-
1. **Remove Demo Code**: The `logistics/` folder and `seeder.ts` are examples. Replace with actual cleaner implementation.
58+
1. **Incremental Commits & PRs**: Always implement changes in small commits grouped into reviewable PRs. After implementing each part:
59+
- Stage files with `git add`
60+
- Stop and wait for user confirmation before committing
61+
- Only commit after explicit user approval
62+
- Use conventional commits: `<type>(<scope>): <description>`
63+
- When enough commits are accumulated (3-5 related commits), STOP and tell user to create PR before continuing
5964

60-
2. **Package Metadata**: Update `package.json` name from `jobnik-worker-boilerplate` to `cleaner`.
65+
2. **Remove Demo Code**: The `logistics/` folder and `seeder.ts` are examples. Replace with actual cleaner implementation.
6166

62-
3. **Type Safety**: Define job/stage types in `src/cleaner/types.ts` and update `worker.ts` with correct generic parameters.
67+
3. **Package Metadata**: Update `package.json` name from `cleaner` to `cleaner`.
6368

64-
4. **Path Aliases**: Use `@common/` for imports from `src/common/`.
69+
4. **Type Safety**: Define job/stage types in `src/cleaner/types.ts` and update `worker.ts` with correct generic parameters.
6570

66-
5. **Endpoints**: `/metrics` (Prometheus), `/liveness` (health check).
71+
5. **Path Aliases**: Use `@common/` for imports from `src/common/`.
72+
73+
6. **Endpoints**: `/metrics` (Prometheus), `/liveness` (health check).
6774

6875
## Common Tasks
6976

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export const workerBuilder: FactoryFunction<IWorker> = (container: DependencyCon
156156

157157
### 5. Rename Throughout the Project
158158

159-
Update references to `jobnik-worker-boilerplate` in:
159+
Update references to `cleaner` in:
160160
- `package.json` - name, description, author
161161
- `helm/Chart.yaml` - name, description
162162
- `helm/values.yaml` - mclabels, configManagement.name, image.repository

ai-docs/common-patterns.md

Lines changed: 83 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,19 @@ In `common/constants.ts`:
5454

5555
```typescript
5656
export const SERVICES = {
57-
CONFIG: Symbol.for('Config'),
58-
LOGGER: Symbol.for('Logger'),
59-
TRACER: Symbol.for('Tracer'),
60-
METRICS: Symbol.for('Metrics'),
61-
JOBNIK_SDK: Symbol.for('JobnikSDK'),
62-
WORKER: Symbol.for('Worker'),
57+
CONFIG: Symbol('Config'),
58+
LOGGER: Symbol('Logger'),
59+
TRACER: Symbol('Tracer'),
60+
METRICS: Symbol('Metrics'),
61+
JOBNIK_SDK: Symbol('JobnikSDK'),
62+
WORKER: Symbol('Worker'),
6363
// Add new tokens here
64-
CLEANER_SERVICE: Symbol.for('CleanerService'),
65-
} as const;
64+
CLEANER_SERVICE: Symbol('CleanerService'),
65+
} satisfies Record<string, symbol>;
6666
```
6767

68+
**Note**: Strategy classes are registered using their task type string directly (e.g., `'tiles-deletion'`) rather than Symbol tokens. This eliminates the need for an additional mapping layer.
69+
6870
## Task Handling
6971

7072
### Task Handler Structure
@@ -170,13 +172,81 @@ export class MyService {
170172

171173
```
172174
config/
173-
default.json # Base config (always loaded)
174-
development.json # Merged when NODE_ENV=development
175-
production.json # Merged when NODE_ENV=production
176-
test.json # Merged when NODE_ENV=test
177-
local.json # Local overrides (gitignored)
175+
default.json # Base config (always loaded)
176+
development.json # Merged when NODE_ENV=development
177+
production.json # Merged when NODE_ENV=production
178+
test.json # Merged when NODE_ENV=test
179+
local.json # Local overrides (gitignored)
180+
custom-environment-variables.json # Environment variable mappings
181+
helm/
182+
values.yaml # Helm chart default values
183+
local.yaml # Local Helm overrides (gitignored)
184+
templates/configmap.yaml # ConfigMap template
178185
```
179186

187+
### Adding New Configuration Values
188+
189+
**IMPORTANT**: When adding new configuration values, you MUST update ALL configuration files to maintain sync across all deployment levels:
190+
191+
1. **`config/default.json`** - Add the configuration with default values
192+
2. **`config/custom-environment-variables.json`** - Add environment variable mappings
193+
3. **`helm/values.yaml`** - Add Helm chart values
194+
4. **`helm/values-local.yaml`** - Add local development values (if needed)
195+
5. **`helm/templates/configmap.yaml`** - Add to ConfigMap template
196+
197+
**Example:**
198+
199+
Adding a new `queue.jobManagerBaseUrl` configuration:
200+
201+
**1. config/default.json**
202+
203+
```json
204+
{
205+
"queue": {
206+
"jobManagerBaseUrl": "http//localhost:8080"
207+
}
208+
}
209+
```
210+
211+
**2. config/custom-environment-variables.json**
212+
213+
```json
214+
{
215+
"queue": {
216+
"jobManagerBaseUrl": "QUEUE_JOB_MANAGER_BASE_URL"
217+
}
218+
}
219+
```
220+
221+
**3. helm/values.yaml**
222+
223+
```yaml
224+
env:
225+
queue:
226+
jobManagerBaseUrl: 'http//localhost:8080'
227+
```
228+
229+
**4. helm/local.yaml** (for local development)
230+
231+
```yaml
232+
env:
233+
queue:
234+
jobManagerBaseUrl: 'http://localhost:8080'
235+
```
236+
237+
**5. helm/templates/configmap.yaml**
238+
239+
```yaml
240+
data:
241+
QUEUE_JOB_MANAGER_BASE_URL: { { .Values.env.queue.jobManagerBaseUrl | quote } }
242+
```
243+
244+
This ensures configuration works correctly in:
245+
246+
- Local development (default.json, local.json)
247+
- CI/CD environments (environment variables)
248+
- Kubernetes deployments (Helm charts)
249+
180250
## Error Handling
181251
182252
### In Task Handlers

0 commit comments

Comments
 (0)