diff --git a/java/google/registry/env/production/default/WEB-INF/cron.xml b/java/google/registry/env/production/default/WEB-INF/cron.xml
index 4b8a40af8..d23b154d8 100644
--- a/java/google/registry/env/production/default/WEB-INF/cron.xml
+++ b/java/google/registry/env/production/default/WEB-INF/cron.xml
@@ -256,18 +256,9 @@
Create ICANN activity and transaction reports for last month, storing them in
gs://domain-registry-alpha-reporting/icann/monthly/yyyy-MM
+ Upon success, enqueues the icannReportingUpload task to POST these files to ICANN.
2 of month 09:00
backend
-
-
-
-
- Upload ICANN activity and transaction reports for last month to ICANN, fetching them from
- gs://domain-registry-alpha-reporting/icann/monthly/yyyy-MM
-
- 4 of month 09:00
- backend
-
diff --git a/java/google/registry/reporting/IcannReportingStagingAction.java b/java/google/registry/reporting/IcannReportingStagingAction.java
index 59906785f..921f47dff 100644
--- a/java/google/registry/reporting/IcannReportingStagingAction.java
+++ b/java/google/registry/reporting/IcannReportingStagingAction.java
@@ -18,17 +18,24 @@ import static google.registry.request.Action.Method.POST;
import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
import static javax.servlet.http.HttpServletResponse.SC_OK;
+import com.google.appengine.api.taskqueue.QueueFactory;
+import com.google.appengine.api.taskqueue.TaskOptions;
+import com.google.appengine.api.taskqueue.TaskOptions.Method;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import com.google.common.net.MediaType;
import google.registry.bigquery.BigqueryJobFailureException;
import google.registry.reporting.IcannReportingModule.ReportType;
+import google.registry.reporting.IcannReportingModule.ReportingSubdir;
import google.registry.request.Action;
import google.registry.request.Response;
import google.registry.request.auth.Auth;
import google.registry.util.FormattingLogger;
import google.registry.util.Retrier;
import javax.inject.Inject;
+import org.joda.time.Duration;
+import org.joda.time.YearMonth;
+import org.joda.time.format.DateTimeFormat;
/**
* Action that generates monthly ICANN activity and transactions reports.
@@ -54,7 +61,10 @@ public final class IcannReportingStagingAction implements Runnable {
static final String PATH = "/_dr/task/icannReportingStaging";
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
+ private static final String CRON_QUEUE = "retryable-cron-tasks";
+ @Inject YearMonth yearMonth;
+ @Inject @ReportingSubdir String subdir;
@Inject ImmutableList reportTypes;
@Inject IcannReportingStager stager;
@Inject Retrier retrier;
@@ -83,6 +93,16 @@ public final class IcannReportingStagingAction implements Runnable {
response.setStatus(SC_OK);
response.setContentType(MediaType.PLAIN_TEXT_UTF_8);
response.setPayload("Completed staging action.");
+
+ logger.infofmt("Enqueueing report upload :");
+ TaskOptions uploadTask = TaskOptions.Builder.withUrl(IcannReportingUploadAction.PATH)
+ .method(Method.POST)
+ .countdownMillis(Duration.standardMinutes(2).getMillis())
+ .param(
+ IcannReportingModule.PARAM_YEAR_MONTH,
+ DateTimeFormat.forPattern("yyyy-MM").print(yearMonth))
+ .param(IcannReportingModule.PARAM_SUBDIR, subdir);
+ QueueFactory.getQueue(CRON_QUEUE).add(uploadTask);
return null;
},
new Retrier.FailureReporter() {
diff --git a/javatests/google/registry/reporting/IcannReportingStagingActionTest.java b/javatests/google/registry/reporting/IcannReportingStagingActionTest.java
index fcc64a4b4..b77485ea2 100644
--- a/javatests/google/registry/reporting/IcannReportingStagingActionTest.java
+++ b/javatests/google/registry/reporting/IcannReportingStagingActionTest.java
@@ -16,6 +16,8 @@ package google.registry.reporting;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
+import static google.registry.testing.TaskQueueHelper.assertNoTasksEnqueued;
+import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -28,7 +30,9 @@ import google.registry.testing.AppEngineRule;
import google.registry.testing.FakeClock;
import google.registry.testing.FakeResponse;
import google.registry.testing.FakeSleeper;
+import google.registry.testing.TaskQueueHelper.TaskMatcher;
import google.registry.util.Retrier;
+import org.joda.time.YearMonth;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -49,6 +53,7 @@ public class IcannReportingStagingActionTest {
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.withLocalModules()
+ .withTaskQueue()
.build();
@Before
@@ -57,8 +62,20 @@ public class IcannReportingStagingActionTest {
when(stager.stageReports(ReportType.TRANSACTIONS)).thenReturn(ImmutableList.of("c", "d"));
}
+ private static void assertUploadTaskEnqueued(String yearMonth, String subDir) throws Exception {
+ TaskMatcher matcher =
+ new TaskMatcher()
+ .url("/_dr/task/icannReportingUpload")
+ .method("POST")
+ .param("yearMonth", yearMonth)
+ .param("subdir", subDir);
+ assertTasksEnqueued("retryable-cron-tasks", matcher);
+ }
+
private IcannReportingStagingAction createAction(ImmutableList reportingMode) {
IcannReportingStagingAction action = new IcannReportingStagingAction();
+ action.yearMonth = new YearMonth(2017, 6);
+ action.subdir = "default/dir";
action.reportTypes = reportingMode;
action.response = response;
action.stager = stager;
@@ -77,6 +94,7 @@ public class IcannReportingStagingActionTest {
.emailResults(
"ICANN Monthly report staging summary [SUCCESS]",
"Completed staging the following 2 ICANN reports:\na\nb");
+ assertUploadTaskEnqueued("2017-06", "default/dir");
}
@Test
@@ -91,6 +109,7 @@ public class IcannReportingStagingActionTest {
.emailResults(
"ICANN Monthly report staging summary [SUCCESS]",
"Completed staging the following 4 ICANN reports:\na\nb\nc\nd");
+ assertUploadTaskEnqueued("2017-06", "default/dir");
}
@Test
@@ -108,6 +127,7 @@ public class IcannReportingStagingActionTest {
.emailResults(
"ICANN Monthly report staging summary [SUCCESS]",
"Completed staging the following 4 ICANN reports:\na\nb\nc\nd");
+ assertUploadTaskEnqueued("2017-06", "default/dir");
}
@Test
@@ -129,5 +149,7 @@ public class IcannReportingStagingActionTest {
"ICANN Monthly report staging summary [FAILURE]",
"Staging failed due to BigqueryJobFailureException: Expected failure,"
+ " check logs for more details.");
+ // Assert no upload task enqueued
+ assertNoTasksEnqueued("retryable-cron-tasks");
}
}