Feature/ Grit-metre - #6
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors the existing scheduler/jobs functionality into a modules/jobs structure, introduces a new “Grit Meter” feature (cron + manual trigger) that performs daily DB-driven updates, and updates project configuration (TypeScript paths, env vars, CI branch targeting) to align with the deployment environment.
Changes:
- Replaced the legacy
src/scheduler/*module/tests with a newsrc/modules/jobs/*module layout and naming (Scheduler*→Jobs*). - Added a new
GritMeterModulewith a daily cron job and an HTTP endpoint to run processing on demand. - Updated config: tsconfig output/paths,
.env.exampledatabase variables, and CI workflow branch trigger.
Reviewed changes
Copilot reviewed 15 out of 17 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tsconfig.json | Switches TS module/target settings and adds path aliases. |
| src/scheduler/scheduler.module.ts | Removes legacy scheduler Nest module (replaced by JobsModule). |
| src/scheduler/scheduler.controller.spec.ts | Removes legacy e2e test coverage for jobs endpoints. |
| src/modules/jobs/jobs.service.ts | Renames/refactors scheduler service into JobsService. |
| src/modules/jobs/jobs.module.ts | Introduces JobsModule wiring for controller/service/runner/repository. |
| src/modules/jobs/jobs.controller.ts | Renames controller to JobsController and rebinds to JobsService. |
| src/modules/jobs/job-runner.service.ts | Keeps job runner behavior while trimming inline comments/formatting. |
| src/modules/jobs/entities/job.entity.ts | Adds JobEntity under the new module path. |
| src/modules/jobs/dto/create-job.dto.ts | Simplifies DTO validation (notably scheduling). |
| src/modules/grit-meter/grit-meter.service.ts | Adds daily grit-meter processing logic, feature flag, and webhook dispatch. |
| src/modules/grit-meter/grit-meter.module.ts | Registers grit-meter controller/service and exports the service. |
| src/modules/grit-meter/grit-meter.controller.ts | Adds POST /grit-meter/process endpoint to trigger processing. |
| src/guards/api-key.guard.ts | Removes old guard location (moved under src/common). |
| src/common/guards/api-key.guard.ts | Adds guard in shared location and supports SCHEDULER_SERVICE_API_KEY. |
| src/app.module.ts | Wires JobsModule + GritMeterModule, updates DB config/env keys, sets global API key guard. |
| .github/workflows/main.yml | Changes CI trigger branch from main to production. |
| .env.example | Updates env variable names/defaults and adds webhook/API key examples. |
Suppressed comments (2)
src/modules/jobs/dto/create-job.dto.ts:68
schedulingis now an untypedanywith no validation. Since downstream scheduling logic relies on keys likeexecute_at(oneoff) andcron(recurring), invalid payloads can be accepted and then silently never run (or log warnings only). Consider restoring conditional validation (e.g.,ValidateIf+ nested DTOs or a custom validator) so the API rejects malformed schedules at the boundary.
src/modules/jobs/jobs.controller.ts:12- The jobs API was renamed/restructured (Scheduler* -> Jobs*), but there are no tests covering
POST /jobs, listing, or deletions anymore (only AppController is tested). Please add/restore controller/e2e coverage for these endpoints to ensure scheduling and persistence behavior remains correct.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+73
to
+77
| for (const link of userLinks) { | ||
| const activityResult: Array<{ activity_count: number }> = await queryRunner.query( | ||
| ` | ||
| SELECT COUNT(*) AS activity_count | ||
| FROM karma_activity_log |
Comment on lines
+45
to
+51
| const queryRunner = this.dataSource.createQueryRunner(); | ||
| await queryRunner.connect(); | ||
|
|
||
| let processedCount = 0; | ||
| let levelDownCount = 0; | ||
|
|
||
| try { |
Comment on lines
+36
to
+40
| async processDailyGritMeter(): Promise<{ processed: number; levelDowns: number }> { | ||
| this.logger.log('Starting Daily Grit Meter / HP Processing'); | ||
|
|
||
| const isEnabled = await this.checkFeatureFlag(); | ||
| if (!isEnabled) { |
Comment on lines
+8
to
+12
| @Post('process') | ||
| async processGritMeter() { | ||
| const result = await this.gritMeterSvc.processDailyGritMeter(); | ||
| return { success: true, ...result }; | ||
| } |
| @@ -1,13 +1,17 @@ | |||
| # MySQL example | |||
| DB_TYPE=mysql | |||
| # Database Config (Matches mulearnbackend) | |||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.