From be4863133efaee38024bef87c6821343dacb2302 Mon Sep 17 00:00:00 2001 From: Ken Stevens Date: Mon, 11 Mar 2019 17:31:03 -0400 Subject: [PATCH] Pointcut parameters and Retrier log (#1236) * Fixed a pointcut parameter list and log an exception that was being swallowed by Retrier * Documentation clarification --- .../fhir/jpa/model/interceptor/api/Pointcut.java | 8 ++++---- .../ca/uhn/fhir/jpa/searchparam/retry/Retrier.java | 13 +++++++++++++ .../BaseSubscriptionDeliverySubscriber.java | 5 ++++- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/interceptor/api/Pointcut.java b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/interceptor/api/Pointcut.java index 45c05f6a8a3..29854a5fa05 100644 --- a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/interceptor/api/Pointcut.java +++ b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/interceptor/api/Pointcut.java @@ -136,9 +136,9 @@ public enum Pointcut { * Hooks may accept the following parameters: *

* *

* Hooks may return void or may return a boolean. If the method returns @@ -149,7 +149,7 @@ public enum Pointcut { * taken for the delivery. *

*/ - SUBSCRIPTION_AFTER_DELIVERY_FAILED("ca.uhn.fhir.jpa.subscription.module.CanonicalSubscription", "ca.uhn.fhir.jpa.subscription.module.subscriber.ResourceDeliveryMessage"), + SUBSCRIPTION_AFTER_DELIVERY_FAILED("ca.uhn.fhir.jpa.subscription.module.subscriber.ResourceDeliveryMessage", "java.lang.Exception"), /** * Invoked immediately after the delivery of a REST HOOK subscription. diff --git a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/retry/Retrier.java b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/retry/Retrier.java index 1ca0f176199..8c2f311064e 100644 --- a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/retry/Retrier.java +++ b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/retry/Retrier.java @@ -24,7 +24,11 @@ import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.time.DateUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.retry.RetryCallback; +import org.springframework.retry.RetryContext; +import org.springframework.retry.RetryListener; import org.springframework.retry.backoff.ExponentialBackOffPolicy; +import org.springframework.retry.listener.RetryListenerSupport; import org.springframework.retry.policy.SimpleRetryPolicy; import org.springframework.retry.support.RetryTemplate; @@ -52,6 +56,15 @@ public class Retrier { SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy(); retryPolicy.setMaxAttempts(theMaxRetries); myRetryTemplate.setRetryPolicy(retryPolicy); + + RetryListener listener = new RetryListenerSupport() { + @Override + public void onError(RetryContext context, RetryCallback callback, Throwable throwable) { + super.onError(context, callback, throwable); + ourLog.error("Retry failure " + context.getRetryCount() + "/" + theMaxRetries, throwable); + } + }; + myRetryTemplate.registerListener(listener); } public T runWithRetry() { diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/subscriber/BaseSubscriptionDeliverySubscriber.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/subscriber/BaseSubscriptionDeliverySubscriber.java index ab87e6eb0c8..820a255950a 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/subscriber/BaseSubscriptionDeliverySubscriber.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/subscriber/BaseSubscriptionDeliverySubscriber.java @@ -21,6 +21,7 @@ package ca.uhn.fhir.jpa.subscription.module.subscriber; */ import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.jpa.model.interceptor.api.HookParams; import ca.uhn.fhir.jpa.model.interceptor.api.IInterceptorBroadcaster; import ca.uhn.fhir.jpa.model.interceptor.api.Pointcut; import ca.uhn.fhir.jpa.subscription.module.cache.ActiveSubscription; @@ -79,7 +80,9 @@ public abstract class BaseSubscriptionDeliverySubscriber implements MessageHandl ourLog.error(errorMsg, e); // Interceptor call: SUBSCRIPTION_AFTER_DELIVERY - if (!myInterceptorBroadcaster.callHooks(Pointcut.SUBSCRIPTION_AFTER_DELIVERY_FAILED, msg, msg.getSubscription(), e)) { + HookParams hookParams = new HookParams() + .add(ResourceDeliveryMessage.class, msg).add(Exception.class, e); + if (!myInterceptorBroadcaster.callHooks(Pointcut.SUBSCRIPTION_AFTER_DELIVERY_FAILED, hookParams)) { return; }