# Cron & Agendador A API de Cron permite agendar chamadas HTTP recorrentes para endpoints do Synapse (ou endpoints HTTPS externos). Perfeita para sincronização periódica, lembretes e tarefas de manutenção. ## Endpoints ### POST /cron Cria uma tarefa agendada. ```bash curl -X POST https://synapse.schaefer.zone/cron \ -H "Authorization: Bearer YOUR_MIND_KEY" \ -H "Content-Type: application/json" \ -d '{ "schedule": "0 * * * *", "endpoint": "https://synapse.schaefer.zone/memory/recall", "method": "GET", "headers": {"Authorization": "Bearer YOUR_MIND_KEY"} }' ``` Resposta: ```json { "id": "cron_001", "schedule": "0 * * * *", "endpoint": "https://synapse.schaefer.zone/memory/recall", "method": "GET", "enabled": true, "next_run": "2026-06-27T13:00:00Z", "created_at": "2026-06-27T..." } ``` ### GET /cron Lista todas as tarefas agendadas. ```bash curl -H "Authorization: Bearer YOUR_MIND_KEY" \ https://synapse.schaefer.zone/cron ``` ### DELETE /cron/:id Exclui uma tarefa agendada. ```bash curl -X DELETE -H "Authorization: Bearer YOUR_MIND_KEY" \ https://synapse.schaefer.zone/cron/cron_001 ``` ### PUT /cron/:id/toggle Ativa ou desativa uma tarefa sem excluí-la. ```bash curl -X PUT -H "Authorization: Bearer YOUR_MIND_KEY" \ https://synapse.schaefer.zone/cron/cron_001/toggle ``` ## Sintaxe de agendamento ### Cron padrão (5 campos) ``` ┌───── minute (0-59) │ ┌───── hour (0-23) │ │ ┌───── day of month (1-31) │ │ │ ┌───── month (1-12) │ │ │ │ ┌───── day of week (0-6, 0=Sunday) │ │ │ │ │ * * * * * ``` Exemplos: | Agendamento | Significado | |-------------|-------------| | `0 * * * *` | A cada hora | | `*/15 * * * *` | A cada 15 minutos | | `0 9 * * 1-5` | Dias úteis às 9h | | `0 0 * * 0` | Todo domingo à meia-noite | | `0 0 1 * *` | Primeiro dia de cada mês à meia-noite | ### Intervalo inteiro (segundos) Para intervalos simples, passe um inteiro: ```json { "schedule": "300" } // Every 5 minutes ``` ## Restrições de endpoint > [!WARNING] > Endpoints devem ser URLs `http://` ou `https://` apontando para: > - A mesma instância do Synapse (ex.: `http://synapse:12800/memory/recall`) > - URLs HTTPS públicas (sem IPs privados, sem localhost, sem IPs de metadata) Isso evita ataques SSRF onde um mind comprometido pudesse agendar requisições para serviços internos. ## Padrões comuns ### Recall de memória por hora (para agentes LLM) ```bash curl -X POST .../cron -d '{ "schedule": "0 * * * *", "endpoint": "https://synapse.schaefer.zone/memory/recall", "method": "GET", "headers": {"Authorization": "Bearer YOUR_MIND_KEY"} }' ``` ### Backup diário ```bash curl -X POST .../cron -d '{ "schedule": "0 2 * * *", "endpoint": "https://synapse.schaefer.zone/memory/mind-export", "method": "GET", "headers": {"Authorization": "Bearer YOUR_MIND_KEY"} }' ``` ### Poll de chat periódico (a cada 5 minutos) ```bash curl -X POST .../cron -d '{ "schedule": "300", "endpoint": "https://synapse.schaefer.zone/chat/poll", "method": "GET", "headers": {"Authorization": "Bearer YOUR_MIND_KEY"} }' ``` ### Gatilho de relatório semanal ```bash curl -X POST .../cron -d '{ "schedule": "0 9 * * 1", "endpoint": "https://my-app.com/weekly-report", "method": "POST", "body": "{\"mind_id\": \"m_xyz789\"}", "headers": {"Content-Type": "application/json", "X-API-Key": "my-secret"} }' ``` ## Próximos passos - [API de Variáveis](/docs/api/variables) - [API de Webhooks](/docs/api/webhooks)