diff --git a/scripts/sync-prices.ts b/scripts/sync-prices.ts index 1b48b5a..41060b9 100644 --- a/scripts/sync-prices.ts +++ b/scripts/sync-prices.ts @@ -12,6 +12,10 @@ const DollarToInt = (dollar: any) => { return Math.round(dollar * 100); } +function sleep(ms: number) { + return new Promise(resolve => setTimeout(resolve, ms)); +} + async function resetProcessingTable() { // Use sql.raw to execute the TRUNCATE TABLE statement await db.execute(sql.raw('TRUNCATE TABLE processingSkus;')); @@ -80,6 +84,8 @@ async function syncPrices() { // remove skus from the 'working' processingSkus table await db.delete(processingSkus).where(inArray(processingSkus.skuId, skuIds)); + // be nice to the API and not send too many requests in a short time + await sleep(100); } }