private void purgeNamespace(final PurgeNamespace purgeNamespace) { LogUtil.enhanceLogWithCorrelationId(log, purgeNamespace); final Collection<S> namespaceSelections = selectNamespace(purgeNamespace.getNamespace()); log.info("Running <{}>. Affected collections: <{}>.", purgeNamespace, namespaceSelections); final ActorRef sender = getSender(); namespaceOps.purgeAll(namespaceSelections) .runWith(Sink.head(), materializer) .thenAccept(errors -> { // send response to speed up purge workflow final PurgeNamespaceResponse response; if (errors.isEmpty()) { response = PurgeNamespaceResponse.successful(purgeNamespace.getNamespace(), getResourceType(), purgeNamespace.getDittoHeaders()); } else { LogUtil.enhanceLogWithCorrelationId(log, purgeNamespace); final String namespace = purgeNamespace.getNamespace(); errors.forEach(error -> log.error(error, "Error purging namespace <{}>", namespace)); response = PurgeNamespaceResponse.failed(namespace, getResourceType(), purgeNamespace.getDittoHeaders()); } sender.tell(response, getSelf()); }) .exceptionally(error -> { LogUtil.enhanceLogWithCorrelationId(log, purgeNamespace); log.error(error, "Failed to purge namespace <{}>!", purgeNamespace.getNamespace()); // Reply nothing - DB errors were converted to stream elements and handled return null; }); }
expectMsg(PurgeNamespaceResponse.successful(purgedNamespace, getResourceType(), dittoHeaders));