refresh-scheduler
O que ela faz
Esta skill cria um agendador que atualiza os dados do dashboard em intervalos definidos. Ele pausa quando a aba do navegador fica oculta e atualiza os dados desatualizados quando o usuário volta. É para desenvolvedores que criam dashboards ao vivo que chamam muitas fontes de dados.
Quando usar
- ✓Quando você quer que os dados do dashboard se atualizem a cada poucos minutos, sem recarregar a página manualmente.
- ✓Quando você quer que a atualização pare enquanto a aba está em segundo plano.
- ✓Quando muitos painéis chamam serviços externos e os pedidos devem ser espalhados.
Link da skill
https://github.com/HKUDS/AgentPilot/blob/main/openspace/legacy/v1/showcase/skills/refresh-scheduler/SKILL.mdCopie e cole na sua IA (Claude, ChatGPT ou Cursor) pedindo para seguir as instruções.
Como usar
O jeito mais fácil: copie a mensagem e cole na sua IA. Ela lê a skill e segue as instruções.
Mensagem pronta para colar
Para Claude Code, Codex ou Cursor: rode na pasta do projeto e a skill fica instalada.
Baixe o SKILL.md e coloque na pasta de skills do seu agente.
Exemplo do que pedir para a IA
“Pode atualizar os dados do meu dashboard a cada poucos minutos, mas parar enquanto a aba estiver em segundo plano?”
5 skills novas por semana. 1 minuto de leitura.
Como funciona
O agendador inicia um temporizador para cada painel. Ele pausa todos os temporizadores quando a página fica oculta e os reinicia, com a atualização dos dados desatualizados, quando a página volta a ficar visível.
Conteúdo técnico (SKILL.md original)
Texto original do autor, em inglês, direto do GitHub.
Refresh Scheduler Pattern
The refresh scheduler manages periodic data fetching for all panels, pausing when the tab is hidden and flushing stale data when the user returns.
Implementation
Create src/services/refresh-scheduler.ts:
export interface RefreshRegistration {
name: string;
fn: () => Promise<void>;
intervalMs: number;
condition?: () => boolean;
}
interface RunnerEntry {
timer: ReturnType<typeof setInterval> | null;
intervalMs: number;
fn: () => Promise<void>;
condition?: () => boolean;
lastRun: number;
}
export class RefreshScheduler {
private runners = new Map<string, RunnerEntry>();
private inFlight = new Set<string>();
private hiddenSince = 0;
private visibilityHandler: (() => void) | null = null;
constructor() {
this.visibilityHandler = () => this.onVisibilityChange();
document.addEventListener('visibilitychange', this.visibilityHandler);
}
private onVisibilityChange(): void {
if (document.hidden) {
this.hiddenSince = Date.now();
// Pause all timers
for (const entry of this.runners.values()) {
if (entry.timer) {
clearInterval(entry.timer);
entry.timer = null;
}
}
} else {
// Resume and flush stale
this.flushStaleRefreshes();
for (const [name, entry] of this.runners) {
if (!entry.timer) {
entry.timer = setInterval(() => this.runRefresh(name), entry.intervalMs);
}
}
}
}
private async runRefresh(name: string): Promise<void> {
const entry = this.runners.get(name);
if (!entry) return;
if (this.inFlight.has(name)) return;
if (entry.condition && !entry.condition()) return;
this.inFlight.add(name);
try {
await entry.fn();
entry.lastRun = Date.now();
} catch (err) {
console.error(`[Refresh] ${name} failed:`, err);
} finally {
this.inFlight.delete(name);
}
}
scheduleRefresh(
name: string,
fn: () => Promise<void>,
intervalMs: number,
condition?: () => boolean,
): void {
// Clean up existing
const existing = this.runners.get(name);
if (existing?.timer) clearInterval(existing.timer);
const entry: RunnerEntry = {
timer: null,
intervalMs,
fn,
condition,
lastRun: 0,
};
if (!document.hidden) {
entry.timer = setInterval(() => this.runRefresh(name), intervalMs);
}
this.runners.set(name, entry);
}
/**
* After returning from hidden, flush all runners whose data
* is older than their interval. Stagger to avoid API burst.
*/
flushStaleRefreshes(): void {
if (!this.hiddenSince) return;
const hiddenMs = Date.now() - this.hiddenSince;
this.hiddenSince = 0;
let stagger = 0;
for (const [name, entry] of this.runners) {
if (hiddenMs < entry.intervalMs) continue;
const delay = stagger;
stagger += 150; // 150ms between each flush
setTimeout(() => this.runRefresh(name), delay);
}
}
registerAll(registrations: RefreshRegistration[]): void {
for (const reg of registrations) {
this.scheduleRefresh(reg.name, reg.fn, reg.intervalMs, reg.condition);
}
}
/** Manually trigger a specific refresh immediately */
trigger(name: string): void {
this.runRefresh(name);
}
destroy(): void {
if (this.visibilityHandler) {
document.removeEventListener('visibilitychange', this.visibilityHandler);
}
for (const entry of this.runners.values()) {
if (entry.timer) clearInterval(entry.timer);
}
this.runners.clear();
this.inFlight.clear();
}
}
Usage
// src/main.ts
import { RefreshScheduler } from './services/refresh-scheduler';
const scheduler = new RefreshScheduler();
// Register panel refresh intervals
scheduler.registerAll([
{ name: 'stocks', fn: () => stockPanel.refresh(), intervalMs: 60_000 },
{ name: 'news', fn: () => newsPanel.refresh(), intervalMs: 5 * 60_000 },
{ name: 'email', fn: () => emailPanel.refresh(), intervalMs: 2 * 60_000 },
{ name: 'calendar', fn: () => calendarPanel.refresh(), intervalMs: 5 * 60_000 },
]);
Key Behaviors
- Pause when hidden — stops all intervals when tab is not visible
- Flush on return — refreshes stale panels with 150ms stagger to avoid API burst
- In-flight guard — prevents duplicate requests for the same panel
- Configurable intervals — each panel has its own refresh rate
- **Condi
Perguntas frequentes
Todos os painéis vão atualizar ao mesmo tempo?
Não. O agendador espalha as atualizações para que muitos pedidos não saiam em uma única rajada.
O que acontece se uma atualização ainda estiver em andamento?
O agendador acompanha os pedidos em andamento, então não inicia a mesma atualização duas vezes.
Cada painel pode ter seu próprio intervalo?
Sim. Cada registro define o seu próprio intervalo de atualização.
Detalhes
Descrição original do autor
Manage timed data refresh intervals for all dashboard panels. Handles pause-when-hidden, stale-data flush on visibility restore, and staggered refresh to avoid API bursts.
repo: HKUDS/AgentPilot
Popularidade
- Estrelas no GitHub
- 7,8 mil
- Posição no ranking
- #13079
- Licença
- MIT
- Atualizada em
- 01/11/2026
Comentários
- …
Mais skills deste repositório
agentpilot
7,8 milAjuda seu agente a melhorar um projeto passo a passo, preparando uma tarefa e executando o ciclo do AgentPilot, que propõe, testa e pontua mudanças.
openspace
7,8 milAjuda seu agente a configurar o OpenSpace, uma ferramenta que armazena e busca skills de agentes, e a conectá-la ao seu app de IA pelo MCP.
rsi-arena
7,8 milAjuda seu agente a configurar e rodar testes padrão de benchmark de IA, como AIME e Terminal-Bench, para comparar diferentes métodos de melhoria.
experiment-guide
7,8 milAjuda seu agente a planejar pequenos experimentos, ler seus resultados e registrar descobertas enquanto investiga como melhorar um programa.
Skills parecidas
angular-developer
280 milAjuda seu agente a criar código Angular e a dar conselhos sobre a estrutura do projeto. É útil para iniciar novos projetos, criar partes do código ou melhorar a performance e acessibilidade.
frontend-a11y
280 milAjuda seu agente a tornar interfaces web acessíveis para todos. Ele garante que sites e apps funcionem bem com leitores de tela e navegação por teclado.
frontend-patterns
280 milFaz seu agente aplicar padrões modernos no desenvolvimento frontend. Ele otimiza performance, gerencia estado e segue boas práticas em React e Next.js.