From b7bbf85ad2a1e12a4eba1a219eb058ffd88de7c4 Mon Sep 17 00:00:00 2001 From: Pavlo Tkach <3469726+ptkach@users.noreply.github.com> Date: Thu, 5 Jan 2023 21:45:56 -0500 Subject: [PATCH] Fix billing pipeline first month scheduling (#1891) * Fix billing pipeline first month scheduling * compare to expansion next month * use yoda date comparison * update cursor time to be mid of day --- .../billing/GenerateInvoicesAction.java | 2 +- .../billing/GenerateInvoicesActionTest.java | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/google/registry/reporting/billing/GenerateInvoicesAction.java b/core/src/main/java/google/registry/reporting/billing/GenerateInvoicesAction.java index 9b839f077..b9aceeaa8 100644 --- a/core/src/main/java/google/registry/reporting/billing/GenerateInvoicesAction.java +++ b/core/src/main/java/google/registry/reporting/billing/GenerateInvoicesAction.java @@ -120,7 +120,7 @@ public class GenerateInvoicesAction implements Runnable { .orElse(Cursor.createGlobal(RECURRING_BILLING, START_OF_TIME)) .getCursorTime()); - if (yearMonth.getMonthOfYear() >= currentCursorTime.getMonthOfYear()) { + if (!YearMonth.fromDateFields(currentCursorTime.toDate()).isAfter(yearMonth)) { throw new IllegalStateException( "Latest billing events expansion cycle hasn't finished yet, terminating invoicing" + " pipeline"); diff --git a/core/src/test/java/google/registry/reporting/billing/GenerateInvoicesActionTest.java b/core/src/test/java/google/registry/reporting/billing/GenerateInvoicesActionTest.java index 60be99f53..fafb4f09b 100644 --- a/core/src/test/java/google/registry/reporting/billing/GenerateInvoicesActionTest.java +++ b/core/src/test/java/google/registry/reporting/billing/GenerateInvoicesActionTest.java @@ -168,4 +168,28 @@ class GenerateInvoicesActionTest extends BeamActionTestBase { + " terminating invoicing pipeline"); cloudTasksHelper.assertNoTasksEnqueued("beam-reporting"); } + + @Test + void testSucceedsToGenerateInvoicesFirstDayOfTheYear() throws Exception { + persistResource(Cursor.createGlobal(RECURRING_BILLING, DateTime.parse("2017-01-01T13:15:00Z"))); + action = + new GenerateInvoicesAction( + "test-project", + "test-region", + "staging_bucket", + "billing_bucket", + "REG-INV", + false, + new YearMonth(2016, 12), + emailUtils, + cloudTasksUtils, + clock, + response, + dataflow); + action.run(); + assertThat(response.getContentType()).isEqualTo(MediaType.PLAIN_TEXT_UTF_8); + assertThat(response.getStatus()).isEqualTo(SC_OK); + assertThat(response.getPayload()).isEqualTo("Launched invoicing pipeline: jobid"); + cloudTasksHelper.assertNoTasksEnqueued("beam-reporting"); + } }