Feature/ Grit-metre - #8
Merged
Merged
Conversation
Updated dockerfile
Updated auth
Feature/grit metre
Feature/ Grit-metre
DevFeature/ Grit-metre
There was a problem hiding this comment.
Pull request overview
This PR modernizes the scheduler service by migrating the legacy scheduler/* module into a modules/jobs structure, adding a new “Grit Meter” feature (scheduled + manual trigger), and introducing production-focused deployment/runtime configuration (MySQL, Docker, CI deploy, API-key auth).
Changes:
- Replace the old Scheduler module with a Jobs module (controller/service/entity/runner) and add periodic DB sync to the runner.
- Add Grit Meter module (cron-driven daily processing + manual endpoint) and enforce global API-key authentication.
- Add production deployment assets (Dockerfile, docker-compose, GitHub Actions deploy) and update TypeScript config (CommonJS + path aliases).
Reviewed changes
Copilot reviewed 19 out of 23 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tsconfig.json | Switches TS output to CommonJS, lowers target, adds path aliases. |
| src/scheduler/scheduler.module.ts | Removes legacy Scheduler module. |
| src/scheduler/scheduler.controller.spec.ts | Removes legacy e2e tests for Scheduler controller. |
| src/modules/jobs/jobs.service.ts | Renames service and keeps job persistence + runner scheduling. |
| src/modules/jobs/jobs.module.ts | Introduces Jobs module wiring (controller/service/runner/entity). |
| src/modules/jobs/jobs.controller.ts | Renames controller and routes jobs CRUD endpoints. |
| src/modules/jobs/job-runner.service.ts | Adds DB sync loop + scheduling adjustments + retry/backoff logic changes. |
| src/modules/jobs/entities/job.entity.ts | Adds MySQL-oriented jobs entity schema. |
| src/modules/jobs/dto/create-job.dto.ts | Simplifies DTO validation and removes scheduling subtypes. |
| src/modules/grit-meter/grit-meter.service.ts | Adds daily grit-meter processing cron + DB updates + Discord webhook. |
| src/modules/grit-meter/grit-meter.module.ts | Registers grit-meter controller/service. |
| src/modules/grit-meter/grit-meter.controller.ts | Adds manual trigger endpoint for grit-meter processing. |
| src/common/guards/api-key.guard.ts | Adds API key guard for Bearer token auth. |
| src/app.module.ts | Switches DB config to MySQL via ConfigModule and applies global guard. |
| README.md | Expands API documentation for job endpoints. |
| package.json | Adds @nestjs/config and mysql2 dependencies. |
| package-lock.json | Locks new dependency tree for config + mysql driver. |
| Dockerfile | Adds multi-stage Docker build for production image. |
| docker-compose.yml | Adds compose service for running the scheduler. |
| .github/workflows/main.yml | Adds production deploy workflow via SSH + docker-compose. |
| .env.example | Adds example env configuration for MySQL + API key + Discord webhook. |
| .dockerignore | Adds docker ignore rules for build context. |
Suppressed comments (4)
src/modules/jobs/job-runner.service.ts:201
- When a job fails and a retry is scheduled,
job.statusis never reset from'running'. The next retry will callexecute(), hitif (job.status === 'running') return;, and silently stop all further retries (job remains stuck inrunning). Set the status back to'scheduled'before persisting/scheduling retries so retries can run.
src/modules/jobs/job-runner.service.ts:23 JOB_SYNC_INTERVAL_MSis parsed withparseInt(...)and used directly insetInterval. If the env var is unset/empty/invalid,parseIntcan returnNaN, and Node will treat the interval as0, potentially causing a tight loop and hammering the DB/logs. Validate the parsed value and fall back to a safe default when it’s not a positive finite number.
src/modules/jobs/job-runner.service.ts:266syncWithDb()will reschedule one-off jobs whenever!this.timers.has(job.id). Retry backoff timers are stored under keys like${id}:retry:${attempt}, so a job that’s waiting on a retry will be treated as “not scheduled” and may get re-scheduled immediately (bypassing backoff) or run twice. Consider also checking for pending retry timers before callingscheduleOneOff().
src/modules/jobs/jobs.service.ts:36- Jobs are persisted with
status: 'scheduled'even whenschedulingis missing required fields (e.g.,execute_atfor one-off orcronfor recurring). The runner then skips scheduling and the job stays permanently "scheduled" but never runs. Consider validating the scheduling payload and returning a 400 before saving/scheduling.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+27
to
+28
| run: | | ||
| ssh -o StrictHostKeyChecking=no ubuntu@$REMOTE_IP "cd $PROJECT_PATH && git pull && docker-compose up --build -d" |
Comment on lines
+5
to
+7
| ## API Endpoints | ||
|
|
||
| ### 1. Create a Job |
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.