Change from TaskQueueUtils to CLoudTasksUtils in PublishInvoicesAction (#1410)

* Change from TaskQueueUtils to CLoudTasksUtils in PublishInvoicesAction
This commit is contained in:
Rachel Guan 2021-11-10 10:13:19 -05:00 committed by GitHub
parent 678ca22473
commit 7cbda7e8a4
2 changed files with 23 additions and 13 deletions

View file

@ -23,16 +23,17 @@ import static javax.servlet.http.HttpServletResponse.SC_OK;
import com.google.api.services.dataflow.Dataflow;
import com.google.api.services.dataflow.model.Job;
import com.google.appengine.api.taskqueue.QueueFactory;
import com.google.appengine.api.taskqueue.TaskOptions;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.flogger.FluentLogger;
import com.google.common.net.MediaType;
import google.registry.config.RegistryConfig.Config;
import google.registry.reporting.ReportingModule;
import google.registry.request.Action;
import google.registry.request.Action.Service;
import google.registry.request.Parameter;
import google.registry.request.Response;
import google.registry.request.auth.Auth;
import google.registry.util.CloudTasksUtils;
import java.io.IOException;
import javax.inject.Inject;
import org.joda.time.YearMonth;
@ -65,6 +66,7 @@ public class PublishInvoicesAction implements Runnable {
private final Dataflow dataflow;
private final Response response;
private final YearMonth yearMonth;
private final CloudTasksUtils cloudTasksUtils;
@Inject
PublishInvoicesAction(
@ -74,7 +76,8 @@ public class PublishInvoicesAction implements Runnable {
BillingEmailUtils emailUtils,
Dataflow dataflow,
Response response,
YearMonth yearMonth) {
YearMonth yearMonth,
CloudTasksUtils cloudTasksUtils) {
this.projectId = projectId;
this.jobRegion = jobRegion;
this.jobId = jobId;
@ -82,6 +85,7 @@ public class PublishInvoicesAction implements Runnable {
this.dataflow = dataflow;
this.response = response;
this.yearMonth = yearMonth;
this.cloudTasksUtils = cloudTasksUtils;
}
static final String PATH = "/_dr/task/publishInvoices";
@ -119,10 +123,11 @@ public class PublishInvoicesAction implements Runnable {
}
private void enqueueCopyDetailReportsTask() {
TaskOptions copyDetailTask =
TaskOptions.Builder.withUrl(CopyDetailReportsAction.PATH)
.method(TaskOptions.Method.POST)
.param(PARAM_YEAR_MONTH, yearMonth.toString());
QueueFactory.getQueue(BillingModule.CRON_QUEUE).add(copyDetailTask);
cloudTasksUtils.enqueue(
BillingModule.CRON_QUEUE,
CloudTasksUtils.createPostTask(
CopyDetailReportsAction.PATH,
Service.BACKEND.toString(),
ImmutableMultimap.of(PARAM_YEAR_MONTH, yearMonth.toString())));
}
}

View file

@ -15,7 +15,6 @@
package google.registry.reporting.billing;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued;
import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
import static javax.servlet.http.HttpServletResponse.SC_NOT_MODIFIED;
import static javax.servlet.http.HttpServletResponse.SC_NO_CONTENT;
@ -30,10 +29,13 @@ import com.google.api.services.dataflow.Dataflow.Projects.Locations;
import com.google.api.services.dataflow.Dataflow.Projects.Locations.Jobs;
import com.google.api.services.dataflow.Dataflow.Projects.Locations.Jobs.Get;
import com.google.api.services.dataflow.model.Job;
import com.google.cloud.tasks.v2.HttpMethod;
import com.google.common.net.MediaType;
import google.registry.testing.AppEngineExtension;
import google.registry.testing.CloudTasksHelper;
import google.registry.testing.CloudTasksHelper.TaskMatcher;
import google.registry.testing.FakeResponse;
import google.registry.testing.TaskQueueHelper.TaskMatcher;
import google.registry.util.CloudTasksUtils;
import java.io.IOException;
import org.joda.time.YearMonth;
import org.junit.jupiter.api.BeforeEach;
@ -51,6 +53,8 @@ class PublishInvoicesActionTest {
private final Job expectedJob = new Job();
private final BillingEmailUtils emailUtils = mock(BillingEmailUtils.class);
private final FakeResponse response = new FakeResponse();
private final CloudTasksHelper cloudTasksHelper = new CloudTasksHelper();
private final CloudTasksUtils cloudTasksUtils = cloudTasksHelper.getTestCloudTasksUtils();
private PublishInvoicesAction uploadAction;
@RegisterExtension
@ -72,7 +76,8 @@ class PublishInvoicesActionTest {
emailUtils,
dataflow,
response,
new YearMonth(2017, 10));
new YearMonth(2017, 10),
cloudTasksUtils);
}
@Test
@ -84,9 +89,9 @@ class PublishInvoicesActionTest {
TaskMatcher matcher =
new TaskMatcher()
.url("/_dr/task/copyDetailReports")
.method("POST")
.method(HttpMethod.POST)
.param("yearMonth", "2017-10");
assertTasksEnqueued("retryable-cron-tasks", matcher);
cloudTasksHelper.assertTasksEnqueued("retryable-cron-tasks", matcher);
}
@Test