in flux-common/src/main/java/software/amazon/aws/clients/swf/flux/step/WorkflowStepUtil.java [167:215]
public static StepResult executeHooks(List<WorkflowStepHook> hooks, Map<String, String> hookInput, StepHook.HookType hookType,
String activityName, MetricRecorder fluxMetrics, MetricRecorder hookMetrics) {
for (WorkflowStepHook hook : hooks) {
Map<Method, StepHook> methods = WorkflowStepUtil.getAllMethodsWithAnnotation(hook.getClass(), StepHook.class);
for (Map.Entry<Method, StepHook> method : methods.entrySet()) {
if (method.getValue().hookType() != hookType) {
continue;
}
String hookExecutionTimeMetricName = formatHookExecutionTimeName(hook.getClass().getSimpleName(),
method.getKey().getName(), activityName);
fluxMetrics.startDuration(hookExecutionTimeMetricName);
try {
Object result = method.getKey().invoke(hook, WorkflowStepUtil.generateArguments(hook.getClass(),
method.getKey(),
hookMetrics,
hookInput));
if (result != null) {
log.info("Hook {} for activity {} returned value: {}",
hook.getClass().getSimpleName(), activityName, result);
}
} catch (InvocationTargetException e) {
String message = String.format("Hook %s for activity %s threw an exception (%s)",
hook.getClass().getSimpleName(), activityName, e.getCause().toString());
if (method.getValue().retryOnFailure()) {
message += ", and the hook is configured to retry on failure.";
log.info(message, e.getCause());
return StepResult.retry(message);
} else {
log.info("{}, but the hook is configured to ignore failures.", message, e.getCause());
}
} catch (IllegalAccessException e) {
// IllegalAccessException shouldn't happen, since we only looked for public methods, but we'll handle it
// the same way as if the hook itself threw an exception.
String message = String.format("Hook %s for activity %s threw an exception (%s)",
hook.getClass().getSimpleName(), activityName, e.toString());
if (method.getValue().retryOnFailure()) {
message += ", and the hook is configured to retry on failure.";
log.error(message, e.getCause());
return StepResult.retry(message);
} else {
log.error("{}, but the hook is configured to ignore failures.", message, e.getCause());
}
} finally {
fluxMetrics.endDuration(hookExecutionTimeMetricName);
}
}
}
return null;
}