package com.alterdekim.game.component;

import com.alterdekim.game.repository.OnlineStatusRepository;
import com.alterdekim.game.service.OnlineStatusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class OnlineChecker {

    @Autowired
    private OnlineStatusService statusService;

    @Scheduled(fixedRate = 2000)
    private void checker() {
        long secs = (System.currentTimeMillis() / 1000L) - 20;
        statusService.listPingsOlderThan(secs).forEach(o -> statusService.delete(o));
    }
}