feat: add pricing refresh worker boundary
Quality / test (push) Canceled after 0s

This commit is contained in:
2026-09-09 11:25:07 -04:00
parent 4effebd2f8
commit 39b4aab058
4 changed files with 108 additions and 0 deletions
+53
View File
@@ -0,0 +1,53 @@
export async function runPricingRefreshJob({ job, providerRegistry, pricingService }) {
if (!job || job.type !== 'PRICING_REFRESH') {
throw new Error('Unsupported pricing refresh job.');
}
const provider = providerRegistry?.get(job.providerId);
if (!provider) {
return {
...job,
status: 'FAILED',
error: 'Pricing provider is not configured.',
failedAt: new Date(),
};
}
try {
const observations = await provider.observe({
inventoryItemId: job.inventoryItemId,
productId: job.productId,
conditionId: job.conditionId,
});
const savedObservations = [];
for (const observation of observations) {
savedObservations.push(await pricingService.addObservation({
sellerId: job.sellerId,
...observation,
providerId: provider.id,
inventoryItemId: job.inventoryItemId,
productId: job.productId,
conditionId: job.conditionId,
}));
}
const valuation = await pricingService.calculate({
sellerId: job.sellerId,
inventoryItemId: job.inventoryItemId,
});
return {
...job,
status: 'COMPLETED',
observations: savedObservations,
valuation,
completedAt: new Date(),
};
} catch (error) {
return {
...job,
status: 'FAILED',
error: error instanceof Error ? error.message : 'Pricing refresh failed.',
failedAt: new Date(),
};
}
}