Langsung ke konten
Skillpedia
Pemrograman umum7.8k Β· #13082

smart-poll-loop

Fungsinya

Skill ini menjelaskan loop polling yang melambat saat layanan terus gagal dan kembali cepat setelah berhasil. Skill ini ditujukan untuk pengembang yang memeriksa layanan luar secara berkala.

Kapan dipakai

  • βœ“Saat Anda memeriksa layanan luar dengan timer dan layanan itu kadang gagal.
  • βœ“Saat permintaan gagal yang berulang dapat membebani layanan yang sedang kesulitan.
  • βœ“Saat Anda ingin pemeriksaan kembali ke kecepatan normal segera setelah layanan pulih.

Link skill

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

Salin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.

Cara pakai

Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.

Pesan siap tempel

Gunakan skill ini untuk membantu saya: https://github.com/HKUDS/AgentPilot/blob/main/openspace/legacy/v1/showcase/skills/smart-poll-loop/SKILL.md Baca file SKILL.md di link tersebut dan ikuti instruksinya untuk tugas saya.
Mau AI Anda menemukan skill seperti ini sendiri?Pasang MCP Skillpedia gratis: cukup satu baris, dan AI mencari di antara 15.000+ skill sebelum tiap tugas.Pasang dalam 1 menit β†’

Contoh permintaan ke AI

β€œBisakah Anda memeriksa status server saya setiap menit, tetapi memperlambat pemeriksaan saat terus gagal?”

5 skill baru setiap minggu. 1 menit baca.

Cara kerjanya

Setelah setiap kegagalan, waktu tunggu berlipat dua, sampai batas tertentu. Setelah keberhasilan, loop kembali ke interval normal.

Konten teknis (SKILL.md asli)

Teks asli dari pembuat, dalam bahasa Inggris, langsung dari 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
Pertanyaan umum

Seberapa lama waktu tunggu bisa bertambah?

Skill ini menetapkan pengali maksimum, biasanya empat sampai delapan kali interval normal.

Apakah satu keberhasilan mengatur ulang waktu tunggu?

Ya. Satu pemeriksaan yang berhasil mengembalikan loop ke kecepatan normal.

Apakah loop berhenti mencoba setelah cukup banyak kegagalan?

Loop tetap berjalan pada waktu tunggu terpanjang, sehingga pemeriksaan dilanjutkan saat layanan kembali.

Detail

Deskripsi asli dari pembuat

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

repo: HKUDS/AgentPilot

Popularitas

Bintang GitHub
7.8k
Peringkat
#13082
Lisensi
MIT
Diperbarui
1/11/2026

Apakah skill ini berguna?

0

Masuk untuk memberi suara.

Komentar

  • …

Skill lain dari repositori ini

Skill serupa