From db9a1988bc688407c7957c5e55782f33a76d3de3 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Tue, 3 Nov 2020 06:49:57 +0100 Subject: KB68 Automatic expiry of unconfirmed newsletter subscriptions. Change-Id: Iae05f0cac1bacc7e1929a0b3a72d506241c2ece3 --- .../newsletter/NewsletterSubscriptionExpirer.java | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/main/java/eu/mulk/mulkcms2/benki/newsletter/NewsletterSubscriptionExpirer.java (limited to 'src/main/java/eu') 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); + } + } +} -- cgit v1.2.3