Inject the BigQuery streaming metrics queue

This makes local development easier by allowing a stub to be injected for the
queue.

Based on Justin Graham's PR: https://github.com/google/nomulus/pull/51

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=144439454
This commit is contained in:
mcilwain 2017-01-13 07:20:05 -08:00 committed by Ben McIlwain
parent f7e84b56a0
commit 8f8d67a17b
3 changed files with 16 additions and 3 deletions

View file

@ -14,10 +14,10 @@
package google.registry.monitoring.whitebox;
import static com.google.appengine.api.taskqueue.QueueFactory.getQueue;
import static com.google.appengine.api.taskqueue.TaskOptions.Builder.withUrl;
import com.google.appengine.api.modules.ModulesService;
import com.google.appengine.api.taskqueue.Queue;
import com.google.appengine.api.taskqueue.TaskOptions;
import com.google.appengine.api.taskqueue.TransientFailureException;
import com.google.common.base.Supplier;
@ -36,10 +36,11 @@ public class BigQueryMetricsEnqueuer {
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
public static final String QUEUE = "bigquery-streaming-metrics";
public static final String QUEUE_BIGQUERY_STREAMING_METRICS = "bigquery-streaming-metrics";
@Inject ModulesService modulesService;
@Inject @Named("insertIdGenerator") Supplier<String> idGenerator;
@Inject @Named(QUEUE_BIGQUERY_STREAMING_METRICS) Queue queue;
@Inject BigQueryMetricsEnqueuer() {}
@ -54,7 +55,7 @@ public class BigQueryMetricsEnqueuer {
opts.param(entry.getKey(), entry.getValue());
}
opts.param("tableId", metric.getTableId());
getQueue(QUEUE).add(opts);
queue.add(opts);
} catch (TransientFailureException e) {
// Log and swallow. We may drop some metrics here but this should be rare.
logger.info(e, e.getMessage());