KB68 Automatic expiry of unconfirmed newsletter subscriptions.

Change-Id: Iae05f0cac1bacc7e1929a0b3a72d506241c2ece3
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/newsletter/NewsletterSubscriptionExpirer.java b/src/main/java/eu/mulk/mulkcms2/benki/newsletter/NewsletterSubscriptionExpirer.java
new file mode 100644
index 0000000..43787dc
--- /dev/null
+++ b/src/main/java/eu/mulk/mulkcms2/benki/newsletter/NewsletterSubscriptionExpirer.java
@@ -0,0 +1,25 @@
+package eu.mulk.mulkcms2.benki.newsletter;
+
+import io.quarkus.scheduler.Scheduled;
+import java.time.OffsetDateTime;
+import javax.enterprise.context.Dependent;
+import javax.transaction.Transactional;
+import org.jboss.logging.Logger;
+
+@Dependent
+public class NewsletterSubscriptionExpirer {
+
+  private static final Logger log = Logger.getLogger(NewsletterUnsubscriber.class);
+
+  @Scheduled(every = "PT1H")
+  @Transactional
+  void run() {
+    var subscriptionsDeleted =
+        NewsletterSubscription.delete(
+            "registrationKey IS NOT NULL AND startDate < ?1",
+            OffsetDateTime.now().minusWeeks(1));
+    if (subscriptionsDeleted > 0) {
+      log.infof("%d expired newsletter subscriptions deleted.", subscriptionsDeleted);
+    }
+  }
+}