package cn.reghao.devops.mgr.ws.event;

import cn.reghao.devops.mgr.app.db.query.AppDeployQuery;
import cn.reghao.devops.mgr.app.service.AppRunService;
import cn.reghao.devops.common.agent.app.dto.AppInfo;
import cn.reghao.devops.common.msg.event.EvtAgentStart;

import java.util.List;

/**
 * @author reghao
 * @date 2021-10-15 16:39:48
 */
public class MachineEventService {
    private AppDeployQuery appDeployQuery;
    private AppRunService appRunService;

    public void start(EvtAgentStart evtAgentStart) {
        // 向 agent 发送 EvtAppStat 事件, 获取应用的状态
        String machineId = evtAgentStart.getMachineId();
        List<AppInfo> list = appDeployQuery.getAppsByMachineId(machineId);
        if (!list.isEmpty()) {
            appRunService.getStat(machineId, list);
        }
    }
}
