/*
 * Copyright (c) 2024. Elex. All Rights Reesrved.
 * https://www.elex-project.com/
 */

package kr.pe.elex.examples;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.time.LocalDateTime;
import java.util.concurrent.TimeUnit;

@Slf4j
@Configuration
@EnableScheduling
public class Config {
	@Autowired
	private PersonRepository repository;
	@Scheduled(fixedRate = 1, timeUnit = TimeUnit.MINUTES)
	public void task1(){
		log.info("TASK executed.");
		repository.deleteAllInBatch(repository
				.findByCreatedAtLessThan(LocalDateTime.now().minusMinutes(2)));
	}
}
