Skip to content

Commit

Permalink
Check enrolled agents in last 10 minutes
Browse files Browse the repository at this point in the history
  • Loading branch information
criamico committed Apr 11, 2022
1 parent 7c7c60e commit 25a8750
Showing 1 changed file with 1 addition and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,15 @@ const POLLING_INTERVAL_MS = 5 * 1000; // 5 sec
export const usePollingAgentCount = (policyId: string) => {
const [agentIds, setAgentIds] = useState<string[]>([]);

// Use useRef to guarantee we get the same date on each render
const mountedAt = useRef(Date.now());

const timeout = useRef<number | undefined>(undefined);

useEffect(() => {
let isAborted = false;

const poll = () => {
timeout.current = window.setTimeout(async () => {
const secSinceMounted = Math.ceil((Date.now() - mountedAt.current) / 1000);
const request = await sendGetAgents({
kuery: `${AGENTS_PREFIX}.policy_id:"${policyId}" and ${AGENTS_PREFIX}.enrolled_at >= "now-${secSinceMounted}s"`,
kuery: `${AGENTS_PREFIX}.policy_id:"${policyId}" and ${AGENTS_PREFIX}.enrolled_at >= now-10m`,
showInactive: false,
});

Expand Down

0 comments on commit 25a8750

Please sign in to comment.