Wire baseline computation jobs

This commit is contained in:
dahyeon committed 2026-07-03 01:19:45 -07:00
1 parent 3ef86b0b66
commit 2935a526c7
8 files changed
+418 -4

No files matched your search

@@ -1,4 +1,4 @@
import { Injectable, Logger } from '@nestjs/common';
import { Injectable, Logger, Optional } from '@nestjs/common';
import { FEATURE_SCHEMA_VERSION } from '@persona-lenz/shared';
import { ConnectionService } from '../global/database/connection.service';
import type {
@@ -15,6 +15,7 @@ import {
} from '../riot/riot-api.client';
import {
FEATURE_RECOMPUTE_JOB_NAME,
BASELINE_COMPUTATION_JOB_NAME,
MAX_ANALYSIS_MATCH_COUNT,
normalizeFeatureRecomputeBatchSize,
normalizeRequestedMatchCount,
@@ -22,6 +23,7 @@ import {
USER_ANALYSIS_JOB_NAME,
} from './analysis.constants';
import type {
BaselineComputationJobData,
ExtractedPlayerMatchFeature,
FeatureRecomputeJobData,
SeedAccountPipelineData,
@@ -29,6 +31,7 @@ import type {
UserAnalysisJobData,
} from './analysis.types';
import { FeatureExtractorService } from './feature-extractor.service';
import { MetricBaselineService } from './metric-baseline.service';
import { ProfileBuilderService } from './profile-builder.service';
import { TimelineDerivedService } from './timeline-derived.service';
import { TimelineMetricService } from './timeline-metric.service';
@@ -98,6 +101,8 @@ export class AnalysisPipelineService {
private readonly profileBuilderService: ProfileBuilderService,
private readonly timelineDerivedService: TimelineDerivedService,
private readonly timelineMetricService: TimelineMetricService,
@Optional()
private readonly metricBaselineService?: MetricBaselineService,
) {}
public async processUserAnalysisJob(
@@ -277,6 +282,68 @@ export class AnalysisPipelineService {
}
}
public async processBaselineComputationJob(
data: BaselineComputationJobData,
jobId: string,
options: { isFinalAttempt?: boolean } = {},
): Promise<void> {
const normalizedData = {
...data,
cohort: data.cohort ?? 'MASTER_PLUS',
patch: data.patch?.trim() || 'ALL',
};
try {
await this.updateJob(
jobId,
{
status: 'processing',
stage: 'compute-baselines',
progress: {
fetchedMatches: 0,
totalMatches: 0,
},
},
BASELINE_COMPUTATION_JOB_NAME,
);
if (!this.metricBaselineService) {
throw new Error('Metric baseline service is not available.');
}
const result = await this.metricBaselineService.computeMetricBaselines({
cohort: normalizedData.cohort,
patch: normalizedData.patch,
});
await this.updateJob(
jobId,
{
status: 'completed',
stage: 'completed',
progress: {
fetchedMatches: result.samplesRead,
totalMatches: result.baselinesWritten,
},
completedAt: new Date(),
error: undefined,
},
BASELINE_COMPUTATION_JOB_NAME,
);
} catch (error) {
if (options.isFinalAttempt === true) {
await this.updateJob(
jobId,
{
status: 'failed',
error: this.publicBaselineComputationErrorMessage(),
},
BASELINE_COMPUTATION_JOB_NAME,
);
}
throw error;
}
}
public async processSeedAccountPipeline(
data: SeedAccountPipelineData,
jobId: string,
@@ -972,6 +1039,10 @@ export class AnalysisPipelineService {
return 'Analysis failed during processing.';
}
private publicBaselineComputationErrorMessage(): string {
return 'Baseline computation failed during processing.';
}
private logFinalFailure(
data: UserAnalysisJobData,
jobId: string,