refactor: remove metrics job scheduler#436
Conversation
There was a problem hiding this comment.
Pull request overview
This PR removes the pg-boss–scheduled metrics aggregation/cleanup jobs from the backend, leaving metrics computation available but no longer automatically executed on a schedule. It also removes the METRICS_PER_HOUR configuration surface from docs/config.
Changes:
- Removed metrics-related pg-boss queues, workers, schedules, and configuration (
METRICS_PER_HOUR/metricsPerHour). - Updated job type definitions and job-state reporting/mapping to exclude metrics jobs.
- Updated backend documentation to reflect the removal of metrics scheduling.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| docs/environment-variables.md | Removes METRICS_PER_HOUR from the env var reference. |
| apps/backend/src/metrics/services/metrics-scheduler.service.ts | Removes the metrics cleanup routine previously used by scheduled jobs. |
| apps/backend/src/jobs/repositories/job-schedule.repository.ts | Removes metrics queue-name mappings from pg-boss job state queries. |
| apps/backend/src/jobs/jobs.service.ts | Removes metrics queues/workers/schedules and related interval configuration. |
| apps/backend/src/jobs/jobs.service.spec.ts | Updates unit tests to reflect removal of metrics job scheduling/queues. |
| apps/backend/src/jobs/jobs.module.ts | Removes metrics module selection/import from JobsModule wiring. |
| apps/backend/src/jobs/job-queues.ts | Removes metrics queue constants. |
| apps/backend/src/database/entities/job-schedule-state.entity.ts | Removes metrics/metrics_cleanup from the JobType union. |
| apps/backend/src/config/app.config.ts | Removes METRICS_PER_HOUR validation + config loading and metricsPerHour from IJobsConfig. |
| apps/backend/README.md | Removes METRICS_PER_HOUR from the scheduling configuration table. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
apps/backend/src/jobs/jobs.service.ts:1097
updateQueueMetrics()now initializes gauges only for a subset ofJobTypes, but later setsjobsPausedGaugefor all rows returned bycountPausedSchedules()(no filtering). If legacy paused schedules exist (e.g.metrics), this will re-introduce those label series; and if they are later removed, the gauge series can retain a stale value because it is no longer reset each tick. Filter paused-schedule rows to the samejobTypeslist (or explicitly reset/remove legacy labels) to keep exported metrics consistent.
private async updateQueueMetrics(): Promise<void> {
const jobTypes: JobType[] = ["deal", "retrieval", "data_set_creation", "data_retention_poll", "providers_refresh"];
for (const jobType of jobTypes) {
this.jobsQueuedGauge.set({ job_type: jobType }, 0);
this.jobsRetryScheduledGauge.set({ job_type: jobType }, 0);
this.jobsInFlightGauge.set({ job_type: jobType }, 0);
this.jobsPausedGauge.set({ job_type: jobType }, 0);
this.oldestQueuedAgeGauge.set({ job_type: jobType }, 0);
this.oldestInFlightAgeGauge.set({ job_type: jobType }, 0);
}
const rows = await this.jobScheduleRepository.countBossJobStates(["created", "retry", "active"]);
if (rows.length > 0) {
for (const row of rows) {
const jobType = row.job_type as JobType;
if (!jobTypes.includes(jobType)) continue;
const state = String(row.state).toLowerCase();
if (state === "active") {
this.jobsInFlightGauge.set({ job_type: jobType }, row.count);
} else if (state === "retry") {
this.jobsRetryScheduledGauge.set({ job_type: jobType }, row.count);
} else {
this.jobsQueuedGauge.set({ job_type: jobType }, row.count);
}
}
} else {
this.logger.error({
event: "pgboss_job_state_query_empty",
message:
"pgboss.job returned zero rows for states created/retry/active; metrics will remain at 0. Verify the backend is connected to the expected database and schema.",
});
}
const pausedSchedules = await this.jobScheduleRepository.countPausedSchedules();
for (const row of pausedSchedules) {
this.jobsPausedGauge.set({ job_type: row.job_type }, row.count);
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
* refactor: remove legacy metrics API endpoints and module wiring * refactor: add migration to drop legacy metrics schema Drop metrics_daily table, sp_performance materialized views, their refresh functions, and related enums. Remove corresponding entity files and database module registrations. * test: add e2e test for DropMetricsSchema migration
Summary
This PR removes the metrics job scheduling system from the backend, eliminating the periodic metrics aggregation and cleanup jobs that were previously managed by pg-boss. The metrics calculation functionality remains available but is no longer automatically scheduled.
Breaking Changes
METRICS_PER_HOURis no longer recognized (can be safely removed from.envfiles)metricsandmetrics_cleanupjobs in pg-boss will no longer be processedImplements steps 4, 5 and 10 from #275 (comment)