dnet-applications/apps/dhp-broker-application/src/main/java/eu/dnetlib/broker/cron/ScheduledActions.java

44 lines
1.3 KiB
Java
Raw Normal View History

2020-09-04 14:33:19 +02:00
package eu.dnetlib.broker.cron;
2020-07-02 08:55:42 +02:00
import java.util.Date;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
2020-07-02 08:55:42 +02:00
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
2020-09-04 14:33:19 +02:00
import eu.dnetlib.broker.common.elasticsearch.EventRepository;
import eu.dnetlib.broker.common.subscriptions.SubscriptionRepository;
import eu.dnetlib.broker.matchers.SubscriptionEventMatcher;
2020-07-02 08:55:42 +02:00
@Component
@Profile("!openaire")
2020-07-02 08:55:42 +02:00
public class ScheduledActions {
@Autowired
private EventRepository eventRepository;
@Autowired
private SubscriptionRepository subscriptionRepo;
@Autowired
private SubscriptionEventMatcher subscriptionEventMatcher;
private static final Log log = LogFactory.getLog(ScheduledActions.class);
@Scheduled(cron = "${lbs.task.deleteOldEvents.cron}")
public long deleteExpiredEvents() {
2020-08-20 15:02:30 +02:00
final long n = this.eventRepository.deleteByExpiryDateBetween(0, new Date().getTime());
2020-07-02 08:55:42 +02:00
log.info("Number of deleted expired events: " + n);
return n;
}
@Scheduled(cron = "${lbs.task.subscriptionEventsMatcher.cron}")
public void startSubscriptionEventsMatcher() {
this.subscriptionRepo.findAll().forEach(this.subscriptionEventMatcher::startMatching);
}
}