# Cron & Scheduler Cron API ช่วยให้คุณตั้งเวลาการเรียก HTTP แบบ recurring ไปยัง Synapse endpoint (หรือ external HTTPS endpoint) เหมาะสำหรับ sync เป็นคาบ, การแจ้งเตือน, และงานบำรุงรักษา ## Endpoints ### POST /cron สร้าง task ที่ตั้งเวลาไว้ ```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"} }' ``` Response: ```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 รายการ task ที่ตั้งเวลาไว้ทั้งหมด ```bash curl -H "Authorization: Bearer YOUR_MIND_KEY" \ https://synapse.schaefer.zone/cron ``` ### DELETE /cron/:id ลบ task ที่ตั้งเวลาไว้ ```bash curl -X DELETE -H "Authorization: Bearer YOUR_MIND_KEY" \ https://synapse.schaefer.zone/cron/cron_001 ``` ### PUT /cron/:id/toggle เปิดหรือปิดใช้งาน task โดยไม่ลบ ```bash curl -X PUT -H "Authorization: Bearer YOUR_MIND_KEY" \ https://synapse.schaefer.zone/cron/cron_001/toggle ``` ## รูปแบบ Schedule ### Standard cron (5 fields) ``` ┌───── minute (0-59) │ ┌───── hour (0-23) │ │ ┌───── day of month (1-31) │ │ │ ┌───── month (1-12) │ │ │ │ ┌───── day of week (0-6, 0=Sunday) │ │ │ │ │ * * * * * ``` ตัวอย่าง: | Schedule | ความหมาย | |----------|---------| | `0 * * * *` | ทุกชั่วโมง | | `*/15 * * * *` | ทุก 15 นาที | | `0 9 * * 1-5` | 9 โมงเช้าวันธรรมดา | | `0 0 * * 0` | เที่ยงคืนทุกวันอาทิตย์ | | `0 0 1 * *` | เที่ยงคืนวันแรกของทุกเดือน | ### Integer interval (วินาที) สำหรับช่วงเวลาง่าย ๆ ให้ส่ง integer: ```json { "schedule": "300" } // ทุก 5 นาที ``` ## ข้อจำกัดของ Endpoint > [!WARNING] > Endpoint ต้องเป็น URL แบบ `http://` หรือ `https://` ที่ชี้ไปยัง: > - Synapse instance เดียวกัน (เช่น `http://synapse:12800/memory/recall`) > - Public HTTPS URL (ห้าม private IP, ห้าม localhost, ห้าม metadata IP) สิ่งนี้ป้องกัน SSRF attack ที่ mind ที่ถูกโจมตีอาจตั้งเวลา request ไปยัง internal service ## รูปแบบทั่วไป ### การ recall memory รายชั่วโมง (สำหรับ LLM agent) ```bash curl -X POST .../cron -d '{ "schedule": "0 * * * *", "endpoint": "https://synapse.schaefer.zone/memory/recall", "method": "GET", "headers": {"Authorization": "Bearer YOUR_MIND_KEY"} }' ``` ### สำรองข้อมูลรายวัน ```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 chat เป็นคาบ (ทุก 5 นาที) ```bash curl -X POST .../cron -d '{ "schedule": "300", "endpoint": "https://synapse.schaefer.zone/chat/poll", "method": "GET", "headers": {"Authorization": "Bearer YOUR_MIND_KEY"} }' ``` ### ทริกเกอร์รายงานรายสัปดาห์ ```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"} }' ``` ## ขั้นตอนถัดไป - [Variables API](/docs/api/variables) - [Webhooks API](/docs/api/webhooks)