Task Description
As a developer I need to implement a scheduled job that deletes user accounts which have been inactive for more than 2 years so that I can keep the database clean and reduce unnecessary data retention.
Acceptance Criteria
- A new class (e.g.,
AccountCleanupScheduler) is created in a dedicated schedule package
Additional Information
@SpringBootApplication
@EnableScheduling
public class CodeSparkApplication { ... }
public void deleteInactiveAccountsOlderThanYears(int years) {
LocalDateTime cutoff = LocalDateTime.now().minusYears(years);
List<Account> staleAccounts = accountRepository.findByLastLoginAtBefore(cutoff);
accountRepository.deleteAll(staleAccounts);
}
@Component
public class AccountCleanupScheduler {
private final AccountService accountService;
public AccountCleanupScheduler(AccountService accountService) {
this.accountService = accountService;
}
@Scheduled(cron = "0 0 3 * * ?") // Every day at 3 AM
public void deleteInactiveAccounts() {
accountService.deleteInactiveAccountsOlderThanYears(2);
}
}
Task Description
As a developer I need to implement a scheduled job that deletes user accounts which have been inactive for more than 2 years so that I can keep the database clean and reduce unnecessary data retention.
Acceptance Criteria
AccountCleanupScheduler) is created in a dedicatedschedulepackageAdditional Information