{"title":"Cron & Agendador","slug":"cron","category":"api","summary":"Agende chamadas recorrentes de API — cron jobs que disparam em horários programados, perfeitos para sincronização periódica e lembretes.","audience":["human","llm"],"tags":["api","cron","scheduler","automation"],"difficulty":"intermediate","updated":"2026-06-27","word_count":225,"read_minutes":1,"llm_context":"Auth: Mind Key\nCreate: POST /cron { schedule, endpoint, method?, body?, headers?, enabled? }\nList: GET /cron\nDelete: DELETE /cron/:id\nToggle: PUT /cron/:id/toggle\nSchedule: 5-field cron (minute hour day month day-of-week) OR integer interval (seconds)\nEndpoint: must be http(s) URL, same Synapse instance OR public HTTPS (no private IPs)\nPattern: schedule /memory/recall every hour, /chat/poll every 5 min, etc.\n","lang":"pt","translated":true,"requested_lang":"pt","content_markdown":"\n# Cron & Agendador\n\nA API de Cron permite agendar chamadas HTTP recorrentes para endpoints do\nSynapse (ou endpoints HTTPS externos). Perfeita para sincronização periódica,\nlembretes e tarefas de manutenção.\n\n## Endpoints\n\n### POST /cron\n\nCria uma tarefa agendada.\n\n```bash\ncurl -X POST https://synapse.schaefer.zone/cron \\\n  -H \"Authorization: Bearer YOUR_MIND_KEY\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"schedule\": \"0 * * * *\",\n    \"endpoint\": \"https://synapse.schaefer.zone/memory/recall\",\n    \"method\": \"GET\",\n    \"headers\": {\"Authorization\": \"Bearer YOUR_MIND_KEY\"}\n  }'\n```\n\nResposta:\n\n```json\n{\n  \"id\": \"cron_001\",\n  \"schedule\": \"0 * * * *\",\n  \"endpoint\": \"https://synapse.schaefer.zone/memory/recall\",\n  \"method\": \"GET\",\n  \"enabled\": true,\n  \"next_run\": \"2026-06-27T13:00:00Z\",\n  \"created_at\": \"2026-06-27T...\"\n}\n```\n\n### GET /cron\n\nLista todas as tarefas agendadas.\n\n```bash\ncurl -H \"Authorization: Bearer YOUR_MIND_KEY\" \\\n     https://synapse.schaefer.zone/cron\n```\n\n### DELETE /cron/:id\n\nExclui uma tarefa agendada.\n\n```bash\ncurl -X DELETE -H \"Authorization: Bearer YOUR_MIND_KEY\" \\\n     https://synapse.schaefer.zone/cron/cron_001\n```\n\n### PUT /cron/:id/toggle\n\nAtiva ou desativa uma tarefa sem excluí-la.\n\n```bash\ncurl -X PUT -H \"Authorization: Bearer YOUR_MIND_KEY\" \\\n     https://synapse.schaefer.zone/cron/cron_001/toggle\n```\n\n## Sintaxe de agendamento\n\n### Cron padrão (5 campos)\n\n```\n┌───── minute (0-59)\n│ ┌───── hour (0-23)\n│ │ ┌───── day of month (1-31)\n│ │ │ ┌───── month (1-12)\n│ │ │ │ ┌───── day of week (0-6, 0=Sunday)\n│ │ │ │ │\n* * * * *\n```\n\nExemplos:\n\n| Agendamento | Significado |\n|-------------|-------------|\n| `0 * * * *` | A cada hora |\n| `*/15 * * * *` | A cada 15 minutos |\n| `0 9 * * 1-5` | Dias úteis às 9h |\n| `0 0 * * 0` | Todo domingo à meia-noite |\n| `0 0 1 * *` | Primeiro dia de cada mês à meia-noite |\n\n### Intervalo inteiro (segundos)\n\nPara intervalos simples, passe um inteiro:\n\n```json\n{ \"schedule\": \"300\" }  // Every 5 minutes\n```\n\n## Restrições de endpoint\n\n> [!WARNING]\n> Endpoints devem ser URLs `http://` ou `https://` apontando para:\n> - A mesma instância do Synapse (ex.: `http://synapse:12800/memory/recall`)\n> - URLs HTTPS públicas (sem IPs privados, sem localhost, sem IPs de metadata)\n\nIsso evita ataques SSRF onde um mind comprometido pudesse agendar requisições\npara serviços internos.\n\n## Padrões comuns\n\n### Recall de memória por hora (para agentes LLM)\n\n```bash\ncurl -X POST .../cron -d '{\n  \"schedule\": \"0 * * * *\",\n  \"endpoint\": \"https://synapse.schaefer.zone/memory/recall\",\n  \"method\": \"GET\",\n  \"headers\": {\"Authorization\": \"Bearer YOUR_MIND_KEY\"}\n}'\n```\n\n### Backup diário\n\n```bash\ncurl -X POST .../cron -d '{\n  \"schedule\": \"0 2 * * *\",\n  \"endpoint\": \"https://synapse.schaefer.zone/memory/mind-export\",\n  \"method\": \"GET\",\n  \"headers\": {\"Authorization\": \"Bearer YOUR_MIND_KEY\"}\n}'\n```\n\n### Poll de chat periódico (a cada 5 minutos)\n\n```bash\ncurl -X POST .../cron -d '{\n  \"schedule\": \"300\",\n  \"endpoint\": \"https://synapse.schaefer.zone/chat/poll\",\n  \"method\": \"GET\",\n  \"headers\": {\"Authorization\": \"Bearer YOUR_MIND_KEY\"}\n}'\n```\n\n### Gatilho de relatório semanal\n\n```bash\ncurl -X POST .../cron -d '{\n  \"schedule\": \"0 9 * * 1\",\n  \"endpoint\": \"https://my-app.com/weekly-report\",\n  \"method\": \"POST\",\n  \"body\": \"{\\\"mind_id\\\": \\\"m_xyz789\\\"}\",\n  \"headers\": {\"Content-Type\": \"application/json\", \"X-API-Key\": \"my-secret\"}\n}'\n```\n\n## Próximos passos\n\n- [API de Variáveis](/docs/api/variables)\n- [API de Webhooks](/docs/api/webhooks)\n","content_html":"<h1>Cron &amp; Agendador</h1>\n<p>A API de Cron permite agendar chamadas HTTP recorrentes para endpoints do\nSynapse (ou endpoints HTTPS externos). Perfeita para sincronização periódica,\nlembretes e tarefas de manutenção.</p>\n<h2>Endpoints</h2>\n<h3>POST /cron</h3>\n<p>Cria uma tarefa agendada.</p>\n<pre><code class=\"hljs language-bash\">curl -X POST https://synapse.schaefer.zone/cron \\\n  -H <span class=\"hljs-string\">&quot;Authorization: Bearer YOUR_MIND_KEY&quot;</span> \\\n  -H <span class=\"hljs-string\">&quot;Content-Type: application/json&quot;</span> \\\n  -d <span class=\"hljs-string\">&#x27;{\n    &quot;schedule&quot;: &quot;0 * * * *&quot;,\n    &quot;endpoint&quot;: &quot;https://synapse.schaefer.zone/memory/recall&quot;,\n    &quot;method&quot;: &quot;GET&quot;,\n    &quot;headers&quot;: {&quot;Authorization&quot;: &quot;Bearer YOUR_MIND_KEY&quot;}\n  }&#x27;</span></code></pre><p>Resposta:</p>\n<pre><code class=\"hljs language-json\"><span class=\"hljs-punctuation\">{</span>\n  <span class=\"hljs-attr\">&quot;id&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;cron_001&quot;</span><span class=\"hljs-punctuation\">,</span>\n  <span class=\"hljs-attr\">&quot;schedule&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;0 * * * *&quot;</span><span class=\"hljs-punctuation\">,</span>\n  <span class=\"hljs-attr\">&quot;endpoint&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;https://synapse.schaefer.zone/memory/recall&quot;</span><span class=\"hljs-punctuation\">,</span>\n  <span class=\"hljs-attr\">&quot;method&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;GET&quot;</span><span class=\"hljs-punctuation\">,</span>\n  <span class=\"hljs-attr\">&quot;enabled&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-literal\"><span class=\"hljs-keyword\">true</span></span><span class=\"hljs-punctuation\">,</span>\n  <span class=\"hljs-attr\">&quot;next_run&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;2026-06-27T13:00:00Z&quot;</span><span class=\"hljs-punctuation\">,</span>\n  <span class=\"hljs-attr\">&quot;created_at&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;2026-06-27T...&quot;</span>\n<span class=\"hljs-punctuation\">}</span></code></pre><h3>GET /cron</h3>\n<p>Lista todas as tarefas agendadas.</p>\n<pre><code class=\"hljs language-bash\">curl -H <span class=\"hljs-string\">&quot;Authorization: Bearer YOUR_MIND_KEY&quot;</span> \\\n     https://synapse.schaefer.zone/cron</code></pre><h3>DELETE /cron/:id</h3>\n<p>Exclui uma tarefa agendada.</p>\n<pre><code class=\"hljs language-bash\">curl -X DELETE -H <span class=\"hljs-string\">&quot;Authorization: Bearer YOUR_MIND_KEY&quot;</span> \\\n     https://synapse.schaefer.zone/cron/cron_001</code></pre><h3>PUT /cron/:id/toggle</h3>\n<p>Ativa ou desativa uma tarefa sem excluí-la.</p>\n<pre><code class=\"hljs language-bash\">curl -X PUT -H <span class=\"hljs-string\">&quot;Authorization: Bearer YOUR_MIND_KEY&quot;</span> \\\n     https://synapse.schaefer.zone/cron/cron_001/toggle</code></pre><h2>Sintaxe de agendamento</h2>\n<h3>Cron padrão (5 campos)</h3>\n<pre><code class=\"hljs language-plaintext\">┌───── minute (0-59)\n│ ┌───── hour (0-23)\n│ │ ┌───── day of month (1-31)\n│ │ │ ┌───── month (1-12)\n│ │ │ │ ┌───── day of week (0-6, 0=Sunday)\n│ │ │ │ │\n* * * * *</code></pre><p>Exemplos:</p>\n<table>\n<thead>\n<tr>\n<th>Agendamento</th>\n<th>Significado</th>\n</tr>\n</thead>\n<tbody><tr>\n<td><code>0 * * * *</code></td>\n<td>A cada hora</td>\n</tr>\n<tr>\n<td><code>*/15 * * * *</code></td>\n<td>A cada 15 minutos</td>\n</tr>\n<tr>\n<td><code>0 9 * * 1-5</code></td>\n<td>Dias úteis às 9h</td>\n</tr>\n<tr>\n<td><code>0 0 * * 0</code></td>\n<td>Todo domingo à meia-noite</td>\n</tr>\n<tr>\n<td><code>0 0 1 * *</code></td>\n<td>Primeiro dia de cada mês à meia-noite</td>\n</tr>\n</tbody></table>\n<h3>Intervalo inteiro (segundos)</h3>\n<p>Para intervalos simples, passe um inteiro:</p>\n<pre><code class=\"hljs language-json\"><span class=\"hljs-punctuation\">{</span> <span class=\"hljs-attr\">&quot;schedule&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;300&quot;</span> <span class=\"hljs-punctuation\">}</span>  <span class=\"hljs-comment\">// Every 5 minutes</span></code></pre><h2>Restrições de endpoint</h2>\n<div class=\"callout callout-warn\">Endpoints devem ser URLs `http://` ou `https://` apontando para:</div><p>Isso evita ataques SSRF onde um mind comprometido pudesse agendar requisições\npara serviços internos.</p>\n<h2>Padrões comuns</h2>\n<h3>Recall de memória por hora (para agentes LLM)</h3>\n<pre><code class=\"hljs language-bash\">curl -X POST .../cron -d <span class=\"hljs-string\">&#x27;{\n  &quot;schedule&quot;: &quot;0 * * * *&quot;,\n  &quot;endpoint&quot;: &quot;https://synapse.schaefer.zone/memory/recall&quot;,\n  &quot;method&quot;: &quot;GET&quot;,\n  &quot;headers&quot;: {&quot;Authorization&quot;: &quot;Bearer YOUR_MIND_KEY&quot;}\n}&#x27;</span></code></pre><h3>Backup diário</h3>\n<pre><code class=\"hljs language-bash\">curl -X POST .../cron -d <span class=\"hljs-string\">&#x27;{\n  &quot;schedule&quot;: &quot;0 2 * * *&quot;,\n  &quot;endpoint&quot;: &quot;https://synapse.schaefer.zone/memory/mind-export&quot;,\n  &quot;method&quot;: &quot;GET&quot;,\n  &quot;headers&quot;: {&quot;Authorization&quot;: &quot;Bearer YOUR_MIND_KEY&quot;}\n}&#x27;</span></code></pre><h3>Poll de chat periódico (a cada 5 minutos)</h3>\n<pre><code class=\"hljs language-bash\">curl -X POST .../cron -d <span class=\"hljs-string\">&#x27;{\n  &quot;schedule&quot;: &quot;300&quot;,\n  &quot;endpoint&quot;: &quot;https://synapse.schaefer.zone/chat/poll&quot;,\n  &quot;method&quot;: &quot;GET&quot;,\n  &quot;headers&quot;: {&quot;Authorization&quot;: &quot;Bearer YOUR_MIND_KEY&quot;}\n}&#x27;</span></code></pre><h3>Gatilho de relatório semanal</h3>\n<pre><code class=\"hljs language-bash\">curl -X POST .../cron -d <span class=\"hljs-string\">&#x27;{\n  &quot;schedule&quot;: &quot;0 9 * * 1&quot;,\n  &quot;endpoint&quot;: &quot;https://my-app.com/weekly-report&quot;,\n  &quot;method&quot;: &quot;POST&quot;,\n  &quot;body&quot;: &quot;{\\&quot;mind_id\\&quot;: \\&quot;m_xyz789\\&quot;}&quot;,\n  &quot;headers&quot;: {&quot;Content-Type&quot;: &quot;application/json&quot;, &quot;X-API-Key&quot;: &quot;my-secret&quot;}\n}&#x27;</span></code></pre><h2>Próximos passos</h2>\n<ul>\n<li><a href=\"/docs/api/variables\">API de Variáveis</a></li>\n<li><a href=\"/docs/api/webhooks\">API de Webhooks</a></li>\n</ul>\n","urls":{"html":"/docs/api/cron","text":"/docs/api/cron?format=text","json":"/docs/api/cron?format=json","llm":"/docs/api/cron?format=llm"},"translations_available":["en","zh","hi","es","fr","ar","pt","ru","ja","de","it","ko","nl","pl","tr","sv","vi","th","id","uk"]}