package ru.micord.ervu.security.esia.service;

import net.javacrumbs.shedlock.core.SchedulerLock;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import ru.micord.ervu.security.esia.EsiaAuthInfoStore;

/**
 * @author Eduard Tihomirov
 */
@Service
public class EsiaAuthInfoClearShedulerService {
  @Scheduled(cron = "${esia.auth.info.clear.cron:0 0 */1 * * *}")
  @SchedulerLock(name = "clearAuthInfo")
  @Transactional
  public void run() {
    EsiaAuthInfoStore.removeExpiredRefreshToken();
    EsiaAuthInfoStore.removeExpiredAccessToken();
    EsiaAuthInfoStore.removeExpiredState();
  }
}
