package ervu_business_metrics.service.scheduler;

import ervu_business_metrics.config.KafkaEnabledCondition;
import ervu_business_metrics.service.FailedAuthService;
import net.javacrumbs.shedlock.core.SchedulerLock;
import org.springframework.context.annotation.Conditional;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

/**
 * @author gulnaz
 */
@Service
@Conditional(KafkaEnabledCondition.class)
public class FailedAuthSchedulerService {

  private final FailedAuthService failedAuthService;

  public FailedAuthSchedulerService(FailedAuthService failedAuthService) {
    this.failedAuthService = failedAuthService;
  }

  @Scheduled(cron = "${scheduler.failed_auth_cleanup.cron:0 0 0 * * *}")
  @SchedulerLock(name = "clearFailedAuth")
  public void clear() {
    failedAuthService.clear();
  }
}
