본문으로 건너뛰기
Skillpedia
일반 코딩7.8k · #13082

smart-poll-loop

하는 일

이 스킬은 서비스가 계속 실패하면 느려지고 성공하면 다시 빨라지는 폴링 루프를 설명합니다. 외부 서비스를 정기적으로 확인하는 개발자를 위한 스킬입니다.

사용하는 경우

  • ✓외부 서비스를 주기적으로 확인하는데 가끔 실패할 때.
  • ✓실패한 요청이 이미 힘든 서비스에 과부하를 줄 수 있을 때.
  • ✓서비스가 회복되는 즉시 확인 속도가 정상으로 돌아가기를 원할 때.

스킬 링크

https://github.com/HKUDS/AgentPilot/blob/main/openspace/legacy/v1/showcase/skills/smart-poll-loop/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/HKUDS/AgentPilot/blob/main/openspace/legacy/v1/showcase/skills/smart-poll-loop/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“서버 상태를 1분마다 확인하되, 계속 실패하면 확인 간격을 늘려 주실 수 있나요?”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

실패할 때마다 대기 시간이 두 배가 되며, 정해진 한도까지 늘어납니다. 성공하면 루프는 정상 간격으로 돌아갑니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

Smart Poll Loop Pattern

Overview

The Smart Poll Loop pattern implements resilient, adaptive polling for periodic data refresh operations. It combines exponential backoff on consecutive failures with automatic recovery on success, ensuring system resources are protected during outages while maintaining responsiveness when services are healthy.

This pattern is essential for production applications that need to poll external services or APIs continuously but must gracefully handle intermittent failures, rate limits, or temporary service disruptions without overwhelming the system or degrading user experience.

Key Patterns Identified

Pattern 1: Exponential Backoff on Failure

Purpose: Prevent overwhelming failing services with repeated requests while giving them time to recover.

Implementation: Each consecutive failure doubles the polling interval up to a configurable maximum multiplier. This creates exponentially increasing delays: 1x → 2x → 4x → 8x (default max).

Key Elements:

  • consecutiveFailures: Counter tracking sequential failures
  • currentBackoffMultiplier: Current delay multiplier (starts at 1)
  • maxBackoffMultiplier: Upper bound to prevent infinite delays (typically 4-8x)
  • Boolean return from callbacks (true = success, false = failure)

Code Pattern:

// Track failure state per runner
interface RunnerEntry {
  consecutiveFailures: number;
  currentBackoffMultiplier: number;
  intervalMs: number; // base interval
  // ... other fields
}

// On failure, increase backoff
if (!success) {
  entry.consecutiveFailures++;
  const newMultiplier = Math.min(
    Math.pow(2, entry.consecutiveFailures),
    maxBackoffMultiplier
  );
  entry.currentBackoffMultiplier = newMultiplier;
  
  // Reschedule with new interval
  const effectiveInterval = entry.intervalMs * entry.currentBackoffMultiplier;
  scheduleNextRun(effectiveInterval);
}

Pattern 2: Automatic Recovery on Success

Purpose: Immediately restore normal polling frequency when a service recovers, ensuring fresh data flows without unnecessary delay.

Implementation: On any successful callback execution, reset both the failure counter and backoff multiplier to their initial states (0 and 1), then reschedule at the base interval.

Key Elements:

  • Reset logic triggered by success === true or no error thrown
  • Immediate rescheduling at base interval (no waiting for current timer)
  • Logging state transitions for observability

Code Pattern:

if (success) {
  // Auto-recovery: reset backoff and failure count
  if (entry.consecutiveFailures > 0 || entry.currentBackoffMultiplier > 1) {
    entry.consecutiveFailures = 0;
    entry.currentBackoffMultiplier = 1;
    
    // Immediately reschedule at normal interval
    if (!paused && entry.timer) {
      scheduleNextRun(name, entry); // uses base intervalMs
    }
  }
}

Pattern 3: Failure Detection via Boolean Return or Exception

Purpose: Provide flexible signaling for success/failure states, supporting both explicit boolean returns and exception-based error handling.

Implementation: Callbacks can return boolean (explicit success/failure), void (success assumed), or throw exceptions (failure). All three mechanisms trigger the same backoff/recovery logic.

Key Elements:

  • Type signature: () => Promise<boolean | void>
  • true = explicit success, triggers recovery
  • false = explicit failure, triggers backoff
  • void/undefined = implicit success (no news is good news)
  • Exception thrown = failure, triggers backoff

Code Pattern:

let success = true;
try {
  const result = await entry.fn();
  
  // Boolean return indicates explicit success/failure
  if (typeof result === 'boolean') {
    success = result;
  }
  // void/undefined is treated as success
  
  if (success) {
    // trigger recovery...
  } else {
    // trigger backoff...
  }
} catch (err) {
  // Exception is also treated as failure
  success = false;
  // trigger backoff...
}

Pattern 4: Visibility-Aware Scheduling

Purpose: Pause or slow down polling when the page is hidden to conserve resources, then resume or refresh immediately when visible.

Implementation: Listen to visibilitychange events. On hide, clear all timers. On show, either flush stale data (if enough time passed) or resume normal polling.

Key Elements:

  • document.hidden state check
  • pauseWhenHidden flag (full stop vs slower polling
자주 묻는 질문

대기 시간은 얼마나 길어질 수 있나요?

스킬은 보통 정상 간격의 네 배에서 여덟 배 사이의 최대 배수를 설정합니다.

성공하면 대기 시간이 초기화되나요?

네. 한 번 성공한 확인이 루프를 정상 속도로 되돌립니다.

충분히 실패하면 시도를 멈추나요?

루프는 가장 긴 대기 시간으로 계속 실행되므로, 서비스가 돌아오면 확인을 재개합니다.

상세 정보

작성자의 원본 설명

Adaptive polling pattern with exponential backoff on failure, automatic recovery on success, and visibility-aware scheduling

repo: HKUDS/AgentPilot

인기도

GitHub 스타
7.8k
순위
#13082
라이선스
MIT
업데이트
2026. 11. 1.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬