From a769a678faa4d92b72a5f78a1f8de3581f7ba5bb Mon Sep 17 00:00:00 2001 From: musketyr Date: Tue, 17 Jan 2023 09:23:36 +0100 Subject: [PATCH] using Environment instead of ConversionService as a workaround to https://github.com/micronaut-projects/micronaut-core/issues/7948 --- .../agorapulse/worker/sqs/v1/SqsQueuesFactory.java | 4 +--- .../agorapulse/worker/sqs/v2/SqsQueuesFactory.java | 4 +--- .../java/com/agorapulse/worker/local/LocalQueues.java | 11 +++++------ .../worker/processor/MethodJobProcessor.java | 10 +++++----- 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/libs/micronaut-worker-queues-sqs-v1/src/main/java/com/agorapulse/worker/sqs/v1/SqsQueuesFactory.java b/libs/micronaut-worker-queues-sqs-v1/src/main/java/com/agorapulse/worker/sqs/v1/SqsQueuesFactory.java index 5e225d35..708da6d9 100644 --- a/libs/micronaut-worker-queues-sqs-v1/src/main/java/com/agorapulse/worker/sqs/v1/SqsQueuesFactory.java +++ b/libs/micronaut-worker-queues-sqs-v1/src/main/java/com/agorapulse/worker/sqs/v1/SqsQueuesFactory.java @@ -27,7 +27,6 @@ import io.micronaut.context.annotation.Factory; import io.micronaut.context.annotation.Requires; import io.micronaut.context.env.Environment; -import io.micronaut.core.convert.ConversionService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -48,7 +47,6 @@ public JobQueues sqsQueues( AWSCredentialsProvider provider, ObjectMapper mapper, SimpleQueueService service, - Optional> conversionService, Environment environment ) { try { @@ -60,7 +58,7 @@ public JobQueues sqsQueues( } else if (LOGGER.isInfoEnabled()) { LOGGER.info("AWS SDK is not authenticated correctly, Using local job queues"); } - return new LocalQueues(conversionService); + return new LocalQueues(environment); } } diff --git a/libs/micronaut-worker-queues-sqs-v2/src/main/java/com/agorapulse/worker/sqs/v2/SqsQueuesFactory.java b/libs/micronaut-worker-queues-sqs-v2/src/main/java/com/agorapulse/worker/sqs/v2/SqsQueuesFactory.java index 998cf9cb..de2a90fa 100644 --- a/libs/micronaut-worker-queues-sqs-v2/src/main/java/com/agorapulse/worker/sqs/v2/SqsQueuesFactory.java +++ b/libs/micronaut-worker-queues-sqs-v2/src/main/java/com/agorapulse/worker/sqs/v2/SqsQueuesFactory.java @@ -25,7 +25,6 @@ import io.micronaut.context.annotation.Factory; import io.micronaut.context.annotation.Requires; import io.micronaut.context.env.Environment; -import io.micronaut.core.convert.ConversionService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider; @@ -48,7 +47,6 @@ public JobQueues sqsQueues( AwsCredentialsProvider provider, ObjectMapper mapper, SimpleQueueService service, - Optional> conversionService, Environment environment ) { try { @@ -60,7 +58,7 @@ public JobQueues sqsQueues( } else if (LOGGER.isInfoEnabled()) { LOGGER.info("AWS SDK is not authenticated correctly, Using local job queues"); } - return new LocalQueues(conversionService); + return new LocalQueues(environment); } } diff --git a/libs/micronaut-worker/src/main/java/com/agorapulse/worker/local/LocalQueues.java b/libs/micronaut-worker/src/main/java/com/agorapulse/worker/local/LocalQueues.java index fadecdae..1736eb7f 100644 --- a/libs/micronaut-worker/src/main/java/com/agorapulse/worker/local/LocalQueues.java +++ b/libs/micronaut-worker/src/main/java/com/agorapulse/worker/local/LocalQueues.java @@ -19,13 +19,12 @@ import com.agorapulse.worker.queue.JobQueues; import io.micronaut.context.annotation.Secondary; -import io.micronaut.core.convert.ConversionService; +import io.micronaut.context.env.Environment; import io.micronaut.core.type.Argument; import javax.inject.Named; import javax.inject.Singleton; import java.time.Duration; -import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedDeque; import java.util.concurrent.ConcurrentMap; @@ -37,10 +36,10 @@ public class LocalQueues implements JobQueues { private final ConcurrentMap> queues = new ConcurrentHashMap<>(); - private final ConversionService conversionService; + private final Environment environment; - public LocalQueues(Optional> conversionService) { - this.conversionService = conversionService.orElse(ConversionService.SHARED); + public LocalQueues(Environment environment) { + this.environment = environment; } @Override @@ -51,7 +50,7 @@ public void readMessages(String queueName, int maxNumberOfMessages, Duration } for (int i = 0; i < maxNumberOfMessages && !objects.isEmpty(); i++) { - action.accept(conversionService.convertRequired(objects.removeFirst(), argument)); + action.accept(environment.convertRequired(objects.removeFirst(), argument)); } } diff --git a/libs/micronaut-worker/src/main/java/com/agorapulse/worker/processor/MethodJobProcessor.java b/libs/micronaut-worker/src/main/java/com/agorapulse/worker/processor/MethodJobProcessor.java index 2b3d61d0..10503da8 100644 --- a/libs/micronaut-worker/src/main/java/com/agorapulse/worker/processor/MethodJobProcessor.java +++ b/libs/micronaut-worker/src/main/java/com/agorapulse/worker/processor/MethodJobProcessor.java @@ -26,9 +26,9 @@ import com.agorapulse.worker.configuration.MutableJobConfiguration; import io.micronaut.context.ApplicationContext; import io.micronaut.context.BeanContext; +import io.micronaut.context.env.Environment; import io.micronaut.context.processor.ExecutableMethodProcessor; import io.micronaut.core.annotation.AnnotationValue; -import io.micronaut.core.convert.ConversionService; import io.micronaut.core.naming.NameUtils; import io.micronaut.core.util.StringUtils; import io.micronaut.inject.BeanDefinition; @@ -73,7 +73,7 @@ public class MethodJobProcessor implements ExecutableMethodProcessor { private final JobManager jobManager; private final ApplicationConfiguration applicationConfiguration; private final JobScheduler jobScheduler; - private final ConversionService conversionService; + private final Environment environment; private final WorkerConfiguration workerConfiguration; /** @@ -93,7 +93,7 @@ public MethodJobProcessor( JobManager jobManager, ApplicationConfiguration applicationConfiguration, JobScheduler jobScheduler, - Optional> optionalConversionService, + Environment environment, WorkerConfiguration workerConfiguration ) { this.beanContext = beanContext; @@ -102,7 +102,7 @@ public MethodJobProcessor( this.jobManager = jobManager; this.applicationConfiguration = applicationConfiguration; this.jobScheduler = jobScheduler; - this.conversionService = optionalConversionService.orElse(ConversionService.SHARED); + this.environment = environment; this.workerConfiguration = workerConfiguration; } @@ -246,7 +246,7 @@ private String extractQueueNameFromMethod(ExecutableMethod method) { } private Duration convertDuration(String jobName, String durationString, String humanReadableProperty) { - Optional converted = conversionService.convert(durationString, Duration.class); + Optional converted = environment.convert(durationString, Duration.class); if (converted.isPresent()) { return converted.get();