Add feature recompute jobs
This commit is contained in:
1 parent
1a7a1cca68
commit
8668234065
8 files changed
+1176
-36
No files matched your search
@@ -1,10 +1,20 @@
|
||||
import type { Job } from 'bullmq';
|
||||
import { USER_ANALYSIS_JOB_NAME } from './analysis.constants';
|
||||
import type { UserAnalysisJobData } from './analysis.types';
|
||||
import {
|
||||
DEFAULT_FEATURE_RECOMPUTE_BATCH_SIZE,
|
||||
FEATURE_RECOMPUTE_JOB_NAME,
|
||||
MAX_FEATURE_RECOMPUTE_BATCH_SIZE,
|
||||
USER_ANALYSIS_JOB_NAME,
|
||||
} from './analysis.constants';
|
||||
import type {
|
||||
FeatureRecomputeJobData,
|
||||
UserAnalysisJobData,
|
||||
} from './analysis.types';
|
||||
import { AnalysisPipelineService } from './analysis-pipeline.service';
|
||||
import { AnalysisProcessor } from './analysis.processor';
|
||||
|
||||
function createJobData(): UserAnalysisJobData {
|
||||
function createJobData(
|
||||
overrides: Partial<UserAnalysisJobData> = {},
|
||||
): UserAnalysisJobData {
|
||||
return {
|
||||
gameName: 'Hide on bush',
|
||||
tagLine: 'KR1',
|
||||
@@ -12,6 +22,19 @@ function createJobData(): UserAnalysisJobData {
|
||||
regionalRoute: 'asia',
|
||||
queueId: 420,
|
||||
requestedMatchCount: 20,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
function createFeatureRecomputeJobData(
|
||||
overrides: Partial<FeatureRecomputeJobData> = {},
|
||||
): FeatureRecomputeJobData {
|
||||
return {
|
||||
platformRoute: 'kr',
|
||||
queueId: 420,
|
||||
batchSize: 25,
|
||||
puuid: 'target-puuid',
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -42,6 +65,139 @@ describe('AnalysisProcessor', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('delegates feature recompute jobs to the analysis pipeline', async () => {
|
||||
const processFeatureRecomputeJob = jest
|
||||
.fn<
|
||||
Promise<void>,
|
||||
[FeatureRecomputeJobData, string, { isFinalAttempt?: boolean }]
|
||||
>()
|
||||
.mockResolvedValue(undefined);
|
||||
const processor = new AnalysisProcessor({
|
||||
processFeatureRecomputeJob,
|
||||
} as unknown as AnalysisPipelineService);
|
||||
|
||||
await processor.process({
|
||||
attemptsMade: 0,
|
||||
id: 'recompute-job-1',
|
||||
name: FEATURE_RECOMPUTE_JOB_NAME,
|
||||
opts: { attempts: 2 },
|
||||
data: createFeatureRecomputeJobData(),
|
||||
} as Job<unknown>);
|
||||
|
||||
expect(processFeatureRecomputeJob).toHaveBeenCalledWith(
|
||||
createFeatureRecomputeJobData(),
|
||||
'recompute-job-1',
|
||||
{ isFinalAttempt: false },
|
||||
);
|
||||
});
|
||||
|
||||
it('normalizes feature recompute batch size from valid queue payloads', async () => {
|
||||
const processFeatureRecomputeJob = jest.fn().mockResolvedValue(undefined);
|
||||
const processor = new AnalysisProcessor({
|
||||
processFeatureRecomputeJob,
|
||||
} as unknown as AnalysisPipelineService);
|
||||
|
||||
await processor.process({
|
||||
attemptsMade: 0,
|
||||
id: 'recompute-job-1',
|
||||
name: FEATURE_RECOMPUTE_JOB_NAME,
|
||||
opts: { attempts: 2 },
|
||||
data: createFeatureRecomputeJobData({ batchSize: 999 }),
|
||||
} as Job<unknown>);
|
||||
|
||||
expect(processFeatureRecomputeJob).toHaveBeenCalledWith(
|
||||
createFeatureRecomputeJobData({
|
||||
batchSize: MAX_FEATURE_RECOMPUTE_BATCH_SIZE,
|
||||
}),
|
||||
'recompute-job-1',
|
||||
{ isFinalAttempt: false },
|
||||
);
|
||||
});
|
||||
|
||||
it('defaults fractional feature recompute batch sizes below one', async () => {
|
||||
const processFeatureRecomputeJob = jest.fn().mockResolvedValue(undefined);
|
||||
const processor = new AnalysisProcessor({
|
||||
processFeatureRecomputeJob,
|
||||
} as unknown as AnalysisPipelineService);
|
||||
|
||||
await processor.process({
|
||||
attemptsMade: 0,
|
||||
id: 'recompute-job-1',
|
||||
name: FEATURE_RECOMPUTE_JOB_NAME,
|
||||
opts: { attempts: 2 },
|
||||
data: createFeatureRecomputeJobData({ batchSize: 0.5 }),
|
||||
} as Job<unknown>);
|
||||
|
||||
expect(processFeatureRecomputeJob).toHaveBeenCalledWith(
|
||||
createFeatureRecomputeJobData({
|
||||
batchSize: DEFAULT_FEATURE_RECOMPUTE_BATCH_SIZE,
|
||||
}),
|
||||
'recompute-job-1',
|
||||
{ isFinalAttempt: false },
|
||||
);
|
||||
});
|
||||
|
||||
it.each([
|
||||
{
|
||||
data: null,
|
||||
expectedError: 'Feature recompute job data must be an object.',
|
||||
},
|
||||
{
|
||||
data: {
|
||||
...createFeatureRecomputeJobData(),
|
||||
platformRoute: 'invalid',
|
||||
},
|
||||
expectedError: 'Analysis job platformRoute is unsupported.',
|
||||
},
|
||||
{
|
||||
data: {
|
||||
...createFeatureRecomputeJobData(),
|
||||
queueId: 430,
|
||||
},
|
||||
expectedError: 'Analysis job queueId is unsupported.',
|
||||
},
|
||||
{
|
||||
data: {
|
||||
...createFeatureRecomputeJobData(),
|
||||
batchSize: Number.NaN,
|
||||
},
|
||||
expectedError: 'Feature recompute job batchSize must be finite.',
|
||||
},
|
||||
{
|
||||
data: {
|
||||
...createFeatureRecomputeJobData(),
|
||||
puuid: ' ',
|
||||
},
|
||||
expectedError: 'Analysis job puuid is out of range.',
|
||||
},
|
||||
{
|
||||
data: {
|
||||
...createFeatureRecomputeJobData(),
|
||||
puuid: 'x'.repeat(129),
|
||||
},
|
||||
expectedError: 'Analysis job puuid is out of range.',
|
||||
},
|
||||
])(
|
||||
'rejects malformed feature recompute payloads',
|
||||
async ({ data, expectedError }) => {
|
||||
const processFeatureRecomputeJob = jest.fn();
|
||||
const processor = new AnalysisProcessor({
|
||||
processFeatureRecomputeJob,
|
||||
} as unknown as AnalysisPipelineService);
|
||||
|
||||
await expect(
|
||||
processor.process({
|
||||
attemptsMade: 0,
|
||||
id: 'recompute-job-1',
|
||||
name: FEATURE_RECOMPUTE_JOB_NAME,
|
||||
opts: { attempts: 2 },
|
||||
data,
|
||||
} as Job<unknown>),
|
||||
).rejects.toThrow(expectedError);
|
||||
expect(processFeatureRecomputeJob).not.toHaveBeenCalled();
|
||||
},
|
||||
);
|
||||
|
||||
it('rejects jobs without a BullMQ id', async () => {
|
||||
const processor = new AnalysisProcessor({
|
||||
processUserAnalysisJob: jest.fn(),
|
||||
|
||||
Reference in new issue
Block a user