Skip to content

Feature/ Grit-metre - #8

Merged
nashnsulthan merged 21 commits into
productionfrom
dev-server
Aug 4, 2026
Merged

Feature/ Grit-metre#8
nashnsulthan merged 21 commits into
productionfrom
dev-server

Conversation

@nanda-kshr

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI lite review requested due to automatic review settings August 4, 2026 06:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.status is never reset from 'running'. The next retry will call execute(), hit if (job.status === 'running') return;, and silently stop all further retries (job remains stuck in running). 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_MS is parsed with parseInt(...) and used directly in setInterval. If the env var is unset/empty/invalid, parseInt can return NaN, and Node will treat the interval as 0, 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:266
  • syncWithDb() 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 calling scheduleOneOff().
    src/modules/jobs/jobs.service.ts:36
  • Jobs are persisted with status: 'scheduled' even when scheduling is missing required fields (e.g., execute_at for one-off or cron for 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 thread README.md
Comment on lines +5 to +7
## API Endpoints

### 1. Create a Job
@nashnsulthan
nashnsulthan merged commit a313376 into production Aug 4, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants