This commit is contained in:
@@ -1,4 +1,15 @@
|
||||
export async function runPricingRefreshJob({ job, providerRegistry, pricingService }) {
|
||||
export async function processNextPersistentPricingRefreshJob({ jobRepository, pricingRefreshJob }) {
|
||||
const claimed = await jobRepository.claimNext();
|
||||
if (!claimed) return null;
|
||||
|
||||
const result = await pricingRefreshJob({ ...claimed, type: 'PRICING_REFRESH' });
|
||||
if (result.status === 'COMPLETED') {
|
||||
await jobRepository.complete(claimed.id, result.observations, result.valuation);
|
||||
} else {
|
||||
await jobRepository.fail(claimed.id, result.error);
|
||||
}
|
||||
return result;
|
||||
}export async function runPricingRefreshJob({ job, providerRegistry, pricingService }) {
|
||||
if (!job || job.type !== 'PRICING_REFRESH') {
|
||||
throw new Error('Unsupported pricing refresh job.');
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
|
||||
import { createPricingProvider, createPricingProviderRegistry } from '../../api/src/modules/pricing/providers/pricing-provider.js';
|
||||
import { runPricingRefreshJob } from '../src/pricing-refresh-worker.js';
|
||||
import { processNextPersistentPricingRefreshJob, runPricingRefreshJob } from '../src/pricing-refresh-worker.js';
|
||||
|
||||
test('completes a pricing refresh through the provider and pricing service boundaries', async () => {
|
||||
const providerRegistry = createPricingProviderRegistry([
|
||||
@@ -46,3 +46,19 @@ test('fails a refresh clearly when a provider is unavailable', async () => {
|
||||
assert.equal(result.status, 'FAILED');
|
||||
assert.match(result.error, /not configured/);
|
||||
});
|
||||
|
||||
test('persists completed and failed outcomes through the job repository', async () => {
|
||||
const calls = [];
|
||||
const jobRepository = {
|
||||
async claimNext() { return { id: 'job-3', type: 'PRICING_REFRESH', providerId: 'fixture' }; },
|
||||
async complete(id, observations, valuation) { calls.push(['complete', id, observations, valuation]); },
|
||||
async fail(id, error) { calls.push(['fail', id, error]); },
|
||||
};
|
||||
|
||||
await processNextPersistentPricingRefreshJob({
|
||||
jobRepository,
|
||||
async pricingRefreshJob() { return { status: 'COMPLETED', observations: [{ id: 'observation-1' }], valuation: { valueMinor: 2500 } }; },
|
||||
});
|
||||
|
||||
assert.deepEqual(calls, [['complete', 'job-3', [{ id: 'observation-1' }], { valueMinor: 2500 }]]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user