From 35a0947046fbed82d871555e016f129ea74a9564 Mon Sep 17 00:00:00 2001 From: Antoine Clausse Date: Mon, 10 Jun 2024 10:40:29 +0200 Subject: [PATCH] Don't throw cron job when some PayPal collection fails (#18795) * Don't throw cron job when some PayPal collection fails Follow-up of https://github.com/overleaf/internal/pull/18414 and https://github.com/overleaf/internal/pull/18572 This was causing `Heartbeat [cron-web-collect-paypal-prod] is expired.` And the cron to rerun (altogether three times a day, instead of once a day) https://cloudlogging.app.goo.gl/W4qBPFDeTUkRQ8J27 * Update tests GitOrigin-RevId: a6a29cc84c0c72fd86b2e3a9739669d3a5fb0be5 --- .../collect_paypal_past_due_invoice.js | 2 +- .../src/CollectPayPalPastDueInvoiceTest.js | 22 ++++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/services/web/scripts/recurly/collect_paypal_past_due_invoice.js b/services/web/scripts/recurly/collect_paypal_past_due_invoice.js index 69a00d6bef..d942be7130 100644 --- a/services/web/scripts/recurly/collect_paypal_past_due_invoice.js +++ b/services/web/scripts/recurly/collect_paypal_past_due_invoice.js @@ -93,7 +93,7 @@ const main = async () => { const diff = INVOICES_COLLECTED.length - INVOICES_COLLECTED_SUCCESS.length if (diff !== 0) { - throw new Error(`Invoices collection failed for ${diff} invoices`) + logger.warn(`Invoices collection failed for ${diff} invoices`) } return { diff --git a/services/web/test/acceptance/src/CollectPayPalPastDueInvoiceTest.js b/services/web/test/acceptance/src/CollectPayPalPastDueInvoiceTest.js index 1a6ce3c9a2..9ce288da30 100644 --- a/services/web/test/acceptance/src/CollectPayPalPastDueInvoiceTest.js +++ b/services/web/test/acceptance/src/CollectPayPalPastDueInvoiceTest.js @@ -252,11 +252,14 @@ describe('CollectPayPalPastDueInvoice', function () { expect(apiRequestStub.callCount).to.eql(24) }) - it('rejects when some invoice processing failed', async function () { + it("resolves when no invoices are processed so we don't fail in staging", async function () { fakeApiRequests([404]) - await expect(main()).to.be.rejectedWith( - 'Invoices collection failed for 1 invoices' - ) + const r = await main() + expect(r).to.eql({ + INVOICES_COLLECTED: [404], + INVOICES_COLLECTED_SUCCESS: [], + USERS_COLLECTED: ['404'], + }) }) it('doesnt reject when there are no invoices', async function () { @@ -269,10 +272,13 @@ describe('CollectPayPalPastDueInvoice', function () { }) }) - it('resolves when some invoices are partially successful', async function () { + it("resolves when collection is partially successful so we don't fail in prod", async function () { fakeApiRequests([200, 404]) - await expect(main()).to.be.rejectedWith( - 'Invoices collection failed for 1 invoices' - ) + const r = await main() + expect(r).to.eql({ + INVOICES_COLLECTED: [200, 404], + INVOICES_COLLECTED_SUCCESS: [200], + USERS_COLLECTED: ['200', '404'], + }) }) })