
package cn.orionsec.ops.task.fixed;

import cn.orionsec.ops.handler.terminal.manager.TerminalSessionManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Slf4j
@Component
public class TerminalHeartbeatDownChecker {

    @Resource
    private TerminalSessionManager terminalSessionManager;

    @Scheduled(cron = "0 */1 * * * ?")
    private void checkHeartbeat() {
        terminalSessionManager.getSessionHolder().forEach((k, v) -> {
            if (!v.isDown()) {
                return;
            }
            log.info("terminal 心跳检查down token: {}", k);
            try {
                v.heartbeatDownClose();
            } catch (Exception e) {
                log.error("terminal 心跳检查断连失败 token: {}", k, e);
            }
        });
    }

}
