Skip to content

DevFeature/ Grit-metre - #7

Merged
nanda-kshr merged 20 commits into
dev-serverfrom
dev
Aug 4, 2026
Merged

DevFeature/ Grit-metre#7
nanda-kshr merged 20 commits into
dev-serverfrom
dev

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:14
@nanda-kshr
nanda-kshr merged commit ff30cb7 into dev-server Aug 4, 2026
2 checks passed

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 refactors the existing scheduler feature into a JobsModule, adds a new “Grit Meter” module that performs daily DB-driven processing via cron, and introduces production-oriented configuration/deployment changes (MySQL config, API key guard, Docker, GitHub Actions deploy).

Changes:

  • Reworked scheduler functionality into src/modules/jobs/* (service/controller/module, runner sync logic, entity layout, DTO changes) and removed legacy src/scheduler/* module + its e2e spec.
  • Added GritMeterModule with a daily cron task plus a manual trigger endpoint.
  • Added global API-key authentication and updated deployment/config assets (MySQL TypeORM async config, Docker/Docker Compose, production workflow, README/env examples).

Reviewed changes

Copilot reviewed 19 out of 23 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
tsconfig.json Switches TS module/target settings and introduces path aliases.
src/scheduler/scheduler.module.ts Removes legacy SchedulerModule.
src/scheduler/scheduler.controller.spec.ts Removes legacy scheduler e2e spec coverage.
src/modules/jobs/jobs.service.ts Renames SchedulerService to JobsService and keeps persistence/scheduling coordination.
src/modules/jobs/jobs.module.ts Introduces JobsModule wiring (controller/providers/exports).
src/modules/jobs/jobs.controller.ts Renames controller to JobsController and keeps /jobs routes.
src/modules/jobs/job-runner.service.ts Adds periodic DB sync/rescheduling behavior and runner cleanups.
src/modules/jobs/entities/job.entity.ts Adds JobEntity under the jobs module.
src/modules/jobs/dto/create-job.dto.ts Simplifies job creation DTO, loosening scheduling validation.
src/modules/grit-meter/grit-meter.service.ts Adds daily grit-meter cron processing and Discord webhook integration.
src/modules/grit-meter/grit-meter.module.ts Adds grit-meter Nest module.
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 authentication guard.
src/app.module.ts Moves to ConfigModule + MySQL TypeORM async configuration and installs global guard; wires new modules.
README.md Expands API documentation for jobs endpoints.
package.json Adds @nestjs/config and mysql2 dependencies.
package-lock.json Locks new dependencies.
Dockerfile Adds multi-stage build for containerizing the service.
docker-compose.yml Adds compose definition for running the service container.
.github/workflows/main.yml Adds production deploy workflow via SSH.
.env.example Adds environment variable template for DB/auth/Discord config.
.dockerignore Adds ignore rules for Docker builds.
Suppressed comments (3)

src/modules/jobs/job-runner.service.ts:23

  • parseInt can produce NaN (or a very small value) for JOB_SYNC_INTERVAL_MS, and setInterval(..., NaN) effectively becomes a 0ms interval in Node, which can cause a tight loop and DB/log spam. Validate the env var and fall back to a safe default/minimum.
    src/modules/jobs/dto/create-job.dto.ts:6
  • IsDateString is no longer used after removing the scheduling DTOs; leaving it imported will typically fail linting (unused import) and adds noise.
    src/modules/jobs/dto/create-job.dto.ts:68
  • CreateJobDto.scheduling is now completely unvalidated (any). This allows creating jobs without required scheduling fields for their type (e.g. oneoff without execute_at / recurring without cron), which will be persisted as scheduled but never actually scheduled by the runner (it only warns and returns). Consider reintroducing type-specific validation (or a custom validator) so invalid jobs are rejected at the API boundary.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +28 to +34
const apiKey =
this.configService.get<string>('SCHEDULER_SERVICE_API_KEY') ||
this.configService.get<string>('API_KEY');

if (token !== apiKey) {
throw new UnauthorizedException('Invalid API Key');
}
Comment thread src/app.module.ts
Comment on lines +18 to +36
const dbEngine = config.get<string>('DATABASE_ENGINE') || config.get<string>('DB_TYPE') || 'mysql';
const isMysql = dbEngine.includes('mysql') || dbEngine.includes('mariadb');
const entities = [__dirname + '/**/*.entity{.ts,.js}'];

if (!isMysql) {
throw new Error(`Unsupported database engine "${dbEngine}". Please check DATABASE_ENGINE / DB_TYPE in .env`);
}

return {
type: 'mysql' as const,
host: config.get<string>('DATABASE_HOST', 'localhost'),
port: parseInt(config.get<string>('DATABASE_PORT', '3306'), 10),
username: config.get<string>('DATABASE_USER', 'root'),
password: config.get<string>('DATABASE_PASSWORD', ''),
database: config.get<string>('DATABASE_NAME', 'mulearn'),
entities,
synchronize: config.get<string>('DB_SYNC', 'false') === 'true',
logging: config.get<string>('DB_LOGGING', 'false') === 'true',
};
Comment thread README.md
Comment on lines +3 to +5
A robust job scheduling service that allows you to schedule HTTP requests to be executed either once or on a recurring schedule (cron).

## API Endpoints
Comment on lines +14 to +15
- name: Checkout repository
uses: actions/checkout@v3
Comment on lines +18 to +21
- name: Configure SSH key
uses: webfactory/ssh-agent@v0.4.1
with:
ssh-private-key: ${{ secrets.PROD_SSH_PRIVATE_KEY }}
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 Dockerfile
RUN npm ci

COPY . .
RUN npm run build
Comment on lines +73 to +83
for (const link of userLinks) {
const activityResult: Array<{ activity_count: number }> = await queryRunner.query(
`
SELECT COUNT(*) AS activity_count
FROM karma_activity_log
WHERE user_id = ?
AND created_at >= DATE_SUB(CURDATE(), INTERVAL 1 DAY)
AND created_at < CURDATE()
`,
[link.user_id],
);
Comment on lines +36 to +43
async processDailyGritMeter(): Promise<{ processed: number; levelDowns: number }> {
this.logger.log('Starting Daily Grit Meter / HP Processing');

const isEnabled = await this.checkFeatureFlag();
if (!isEnabled) {
this.logger.warn('Grit Meter processing skipped: Feature flag "grit_meter_enabled" is OFF');
return { processed: 0, levelDowns: 0 };
}
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