Move invoice generation to billing bucket and improve emailing

This moves the new pipeline's invoice generation to the billing bucket, under the 'invoices/yyyy-MM' subdirectory.

This also changes the invoice e-mail to use a multipart message that attaches the invoice to the e-mail, to guarantee the correct MIME type and download.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=181746191
This commit is contained in:
larryruili 2018-01-12 08:18:49 -08:00 committed by Ben McIlwain
parent 5726f1dc4e
commit a42f18798e
16 changed files with 477 additions and 133 deletions

View file

@ -53,22 +53,28 @@ public class GenerateInvoicesAction implements Runnable {
private final String projectId;
private final String beamBucketUrl;
private final String invoiceTemplateUrl;
private final YearMonth yearMonth;
private final Dataflow dataflow;
private final Response response;
private final BillingEmailUtils emailUtils;
@Inject
GenerateInvoicesAction(
@Config("projectId") String projectId,
@Config("apacheBeamBucketUrl") String beamBucketUrl,
@Config("invoiceTemplateUrl") String invoiceTemplateUrl,
YearMonth yearMonth,
Dataflow dataflow,
Response response) {
Response response,
BillingEmailUtils emailUtils) {
this.projectId = projectId;
this.beamBucketUrl = beamBucketUrl;
this.invoiceTemplateUrl = invoiceTemplateUrl;
this.yearMonth = yearMonth;
this.dataflow = dataflow;
this.response = response;
this.emailUtils = emailUtils;
}
@Override
@ -88,13 +94,14 @@ public class GenerateInvoicesAction implements Runnable {
.projects()
.templates()
.launch(projectId, params)
.setGcsPath(beamBucketUrl + "/templates/invoicing")
.setGcsPath(invoiceTemplateUrl)
.execute();
logger.infofmt("Got response: %s", launchResponse.getJob().toPrettyString());
String jobId = launchResponse.getJob().getId();
enqueuePublishTask(jobId);
} catch (IOException e) {
logger.warningfmt("Template Launch failed due to: %s", e.getMessage());
emailUtils.sendAlertEmail(String.format("Template Launch failed due to %s", e.getMessage()));
response.setStatus(SC_INTERNAL_SERVER_ERROR);
response.setContentType(MediaType.PLAIN_TEXT_UTF_8);
response.setPayload(String.format("Template launch failed: %s", e.getMessage()));
@ -111,7 +118,9 @@ public class GenerateInvoicesAction implements Runnable {
.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);
.param(BillingModule.PARAM_JOB_ID, jobId)
// Need to pass this through to ensure transitive yearMonth dependencies are satisfied.
.param(BillingModule.PARAM_YEAR_MONTH, yearMonth.toString());
QueueFactory.getQueue(BillingModule.BILLING_QUEUE).add(publishTask);
}
}