Log analysis job failures
This commit is contained in:
1 parent
f447e0c6ab
commit
9d43cc266c
4 files changed
+105
-2
No files matched your search
@@ -1,7 +1,8 @@
|
||||
import { Logger } from '@nestjs/common';
|
||||
import { FEATURE_SCHEMA_VERSION } from '@persona-lenz/shared';
|
||||
import type { ConnectionService } from '../global/database/connection.service';
|
||||
import type { Account } from '../global/database/schemas';
|
||||
import type { RiotApiClient } from '../riot/riot-api.client';
|
||||
import { RiotNotFoundError, type RiotApiClient } from '../riot/riot-api.client';
|
||||
import type { UserAnalysisJobData } from './analysis.types';
|
||||
import { FeatureExtractorService } from './feature-extractor.service';
|
||||
import { AnalysisPipelineService } from './analysis-pipeline.service';
|
||||
@@ -114,6 +115,12 @@ function createStoredAccount(overrides: Partial<Account> = {}): Account {
|
||||
};
|
||||
}
|
||||
|
||||
function suppressLoggerError() {
|
||||
return jest
|
||||
.spyOn(Logger.prototype, 'error')
|
||||
.mockImplementation(() => undefined);
|
||||
}
|
||||
|
||||
interface PipelineHarnessOptions {
|
||||
accountError?: Error;
|
||||
existingMatchRaw?: Record<string, unknown> | null;
|
||||
@@ -334,6 +341,7 @@ describe('AnalysisPipelineService', () => {
|
||||
});
|
||||
|
||||
it('marks the job failed with a public error on the final BullMQ attempt', async () => {
|
||||
const loggerErrorSpy = suppressLoggerError();
|
||||
const { service, updateAnalysisJob } = createPipelineHarness({
|
||||
accountError: new Error('internal host redis.local refused connection'),
|
||||
});
|
||||
@@ -351,5 +359,51 @@ describe('AnalysisPipelineService', () => {
|
||||
status: 'failed',
|
||||
error: 'Analysis failed during processing.',
|
||||
});
|
||||
loggerErrorSpy.mockRestore();
|
||||
});
|
||||
|
||||
it('marks Riot account lookup misses with a public not-found error', async () => {
|
||||
const loggerErrorSpy = suppressLoggerError();
|
||||
const { service, updateAnalysisJob } = createPipelineHarness({
|
||||
accountError: new RiotNotFoundError(404),
|
||||
});
|
||||
|
||||
await expect(
|
||||
service.processUserAnalysisJob(createJobData(), 'analysis-job-1', {
|
||||
isFinalAttempt: true,
|
||||
}),
|
||||
).rejects.toThrow(RiotNotFoundError);
|
||||
|
||||
const failedJobUpdate = updateAnalysisJob.mock.calls.find(
|
||||
([, update]) => asRecord(asRecord(update).$set).status === 'failed',
|
||||
);
|
||||
expect(asRecord(asRecord(failedJobUpdate?.[1]).$set)).toMatchObject({
|
||||
status: 'failed',
|
||||
error: 'Riot account was not found for the selected region.',
|
||||
});
|
||||
loggerErrorSpy.mockRestore();
|
||||
});
|
||||
|
||||
it('logs final pipeline failures with job context', async () => {
|
||||
const loggerErrorSpy = suppressLoggerError();
|
||||
const { service } = createPipelineHarness({
|
||||
accountError: new Error('internal host redis.local refused connection'),
|
||||
});
|
||||
|
||||
await expect(
|
||||
service.processUserAnalysisJob(createJobData(), 'analysis-job-1', {
|
||||
isFinalAttempt: true,
|
||||
}),
|
||||
).rejects.toThrow('internal host redis.local refused connection');
|
||||
|
||||
expect(loggerErrorSpy).toHaveBeenCalledWith(
|
||||
expect.stringContaining('Analysis job failed jobId="analysis-job-1"'),
|
||||
expect.any(String),
|
||||
);
|
||||
expect(loggerErrorSpy.mock.calls[0][0]).toContain(
|
||||
'publicError="Analysis failed during processing."',
|
||||
);
|
||||
|
||||
loggerErrorSpy.mockRestore();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user