Search in sources :

Example 1 with CronJobRun

use of com.redhat.cloud.notifications.models.CronJobRun in project notifications-backend by RedHatInsights.

the class DailyEmailAggregationJob method processAggregateEmails.

List<AggregationCommand> processAggregateEmails(LocalDateTime endTime, CollectorRegistry registry) {
    final CronJobRun lastCronJobRun = emailAggregationResources.getLastCronJobRun();
    LocalDateTime startTime = lastCronJobRun.getLastRun();
    LOG.infof("Collecting email aggregation for period (%s, %s) and type %s", startTime, endTime, DAILY);
    final List<AggregationCommand> pendingAggregationCommands = emailAggregationResources.getApplicationsWithPendingAggregation(startTime, endTime).stream().map(aggregationKey -> new AggregationCommand(aggregationKey, startTime, endTime, DAILY)).collect(Collectors.toList());
    LOG.infof("Finished collecting email aggregations for period (%s, %s) and type %s after %d seconds. %d (accountIds, applications) pairs were processed", startTime, endTime, DAILY, SECONDS.between(endTime, LocalDateTime.now(UTC)), pendingAggregationCommands.size());
    pairsProcessed = Gauge.build().name("aggregator_job_accountid_application_pairs_processed").help("Number of accountId and application pairs processed.").register(registry);
    pairsProcessed.set(pendingAggregationCommands.size());
    return pendingAggregationCommands;
}
Also used : LocalDateTime(java.time.LocalDateTime) Logger(org.jboss.logging.Logger) LocalDateTime(java.time.LocalDateTime) CompletableFuture(java.util.concurrent.CompletableFuture) PushGateway(io.prometheus.client.exporter.PushGateway) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Gauge(io.prometheus.client.Gauge) CronJobRun(com.redhat.cloud.notifications.models.CronJobRun) SECONDS(java.time.temporal.ChronoUnit.SECONDS) CollectorRegistry(io.prometheus.client.CollectorRegistry) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Channel(org.eclipse.microprofile.reactive.messaging.Channel) ActivateRequestContext(javax.enterprise.context.control.ActivateRequestContext) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) DAILY(com.redhat.cloud.notifications.EmailSubscriptionType.DAILY) EmailAggregationResources(com.redhat.cloud.notifications.db.EmailAggregationResources) UTC(java.time.ZoneOffset.UTC) ApplicationScoped(javax.enterprise.context.ApplicationScoped) ConfigProperty(org.eclipse.microprofile.config.inject.ConfigProperty) AggregationCommand(com.redhat.cloud.notifications.models.AggregationCommand) Emitter(org.eclipse.microprofile.reactive.messaging.Emitter) AggregationCommand(com.redhat.cloud.notifications.models.AggregationCommand) CronJobRun(com.redhat.cloud.notifications.models.CronJobRun)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DAILY (com.redhat.cloud.notifications.EmailSubscriptionType.DAILY)1 EmailAggregationResources (com.redhat.cloud.notifications.db.EmailAggregationResources)1 AggregationCommand (com.redhat.cloud.notifications.models.AggregationCommand)1 CronJobRun (com.redhat.cloud.notifications.models.CronJobRun)1 CollectorRegistry (io.prometheus.client.CollectorRegistry)1 Gauge (io.prometheus.client.Gauge)1 PushGateway (io.prometheus.client.exporter.PushGateway)1 IOException (java.io.IOException)1 LocalDateTime (java.time.LocalDateTime)1 UTC (java.time.ZoneOffset.UTC)1 SECONDS (java.time.temporal.ChronoUnit.SECONDS)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1 Collectors (java.util.stream.Collectors)1 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1 ActivateRequestContext (javax.enterprise.context.control.ActivateRequestContext)1