Add publish functionality to billing pipeline

This closes the end-to-end billing pipeline, allowing us to share generated detail reports with registrars via Drive and e-mail the invoicing team a link to the generated invoice.

This also factors out the email configs from ICANN reporting into the common 'misc' config, since we'll likely need alert e-mails for future periodic tasks.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=180805972
This commit is contained in:
larryruili 2018-01-04 09:16:51 -08:00 committed by jianglai
parent 27f12b9390
commit ab5e16ab67
25 changed files with 721 additions and 95 deletions

View file

@ -49,23 +49,28 @@ public class GenerateInvoicesAction implements Runnable {
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
@Inject
@Config("projectId")
String projectId;
@Inject
@Config("apacheBeamBucketUrl")
String beamBucketUrl;
@Inject YearMonth yearMonth;
@Inject Dataflow dataflow;
@Inject Response response;
@Inject
GenerateInvoicesAction() {}
static final String PATH = "/_dr/task/generateInvoices";
private final String projectId;
private final String beamBucketUrl;
private final YearMonth yearMonth;
private final Dataflow dataflow;
private final Response response;
@Inject
GenerateInvoicesAction(
@Config("projectId") String projectId,
@Config("apacheBeamBucketUrl") String beamBucketUrl,
YearMonth yearMonth,
Dataflow dataflow,
Response response) {
this.projectId = projectId;
this.beamBucketUrl = beamBucketUrl;
this.yearMonth = yearMonth;
this.dataflow = dataflow;
this.response = response;
}
@Override
public void run() {
logger.infofmt("Launching invoicing pipeline for %s", yearMonth);
@ -87,13 +92,7 @@ public class GenerateInvoicesAction implements Runnable {
.execute();
logger.infofmt("Got response: %s", launchResponse.getJob().toPrettyString());
String jobId = launchResponse.getJob().getId();
TaskOptions uploadTask =
TaskOptions.Builder.withUrl(PublishInvoicesAction.PATH)
.method(TaskOptions.Method.POST)
// Dataflow jobs tend to take about 10 minutes to complete.
.countdownMillis(Duration.standardMinutes(10).getMillis())
.param(BillingModule.PARAM_JOB_ID, jobId);
QueueFactory.getQueue(BillingModule.BILLING_QUEUE).add(uploadTask);
enqueuePublishTask(jobId);
} catch (IOException e) {
logger.warningfmt("Template Launch failed due to: %s", e.getMessage());
response.setStatus(SC_INTERNAL_SERVER_ERROR);
@ -105,4 +104,14 @@ public class GenerateInvoicesAction implements Runnable {
response.setContentType(MediaType.PLAIN_TEXT_UTF_8);
response.setPayload("Launched dataflow template.");
}
private void enqueuePublishTask(String jobId) {
TaskOptions publishTask =
TaskOptions.Builder.withUrl(PublishInvoicesAction.PATH)
.method(TaskOptions.Method.POST)
// Dataflow jobs tend to take about 10 minutes to complete.
.countdownMillis(Duration.standardMinutes(10).getMillis())
.param(BillingModule.PARAM_JOB_ID, jobId);
QueueFactory.getQueue(BillingModule.BILLING_QUEUE).add(publishTask);
}
}