package org.psesquared.server.util; import java.time.LocalDateTime; import java.time.ZoneOffset; import lombok.RequiredArgsConstructor; import org.psesquared.server.authentication.api.service.AuthenticationService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; /** * A scheduler responsible for running scheduled actions. */ @Component @RequiredArgsConstructor public class Scheduler { /** * The seconds of one day. */ private static final long ONE_DAY = 24 * 60 * (long) 60; /** * The service class of the authentication API. */ @Autowired private final AuthenticationService authenticationService; /** * A scheduled operation that removes all non-verified users from the server, * that haven't been verified since at least 24 hours. *
* Standard: Runs every day at 3 AM. */ @Scheduled(cron = "0 0 3 * * *") public void clean() { authenticationService.deleteInvalidUsersOlderThan( LocalDateTime.now().toEpochSecond(ZoneOffset.UTC) - ONE_DAY); } }