# Cron & Scheduler Cron API は Synapse エンドポイント(または外部 HTTPS エンドポイント)に対する定期 HTTP 呼び出しをスケジュール設定できる API です。定期同期、リマインダー、メンテナンスタスクに最適です。 ## エンドポイント ### POST /cron スケジュールタスクを作成します。 ```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"} }' ``` レスポンス: ```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 すべてのスケジュールタスクを一覧表示します。 ```bash curl -H "Authorization: Bearer YOUR_MIND_KEY" \ https://synapse.schaefer.zone/cron ``` ### DELETE /cron/:id スケジュールタスクを削除します。 ```bash curl -X DELETE -H "Authorization: Bearer YOUR_MIND_KEY" \ https://synapse.schaefer.zone/cron/cron_001 ``` ### PUT /cron/:id/toggle タスクを削除せずに有効化/無効化を切り替えます。 ```bash curl -X PUT -H "Authorization: Bearer YOUR_MIND_KEY" \ https://synapse.schaefer.zone/cron/cron_001/toggle ``` ## スケジュール構文 ### 標準 Cron(5 フィールド) ``` ┌───── 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 * *` | 毎月 1 日の深夜 | ### 整数間隔(秒) 単純な間隔の場合は整数を指定します。 ```json { "schedule": "300" } // Every 5 minutes ``` ## エンドポイントの制限 > [!WARNING] > エンドポイントは以下を指す `http://` または `https://` URL でなければなりません: > - 同じ Synapse インスタンス(例:`http://synapse:12800/memory/recall`) > - パブリック HTTPS URL(プライベート IP、localhost、メタデータ IP は不可) これは、侵害された mind が内部サービスに対してリクエストをスケジュールする SSRF 攻撃を防ぐためです。 ## よくあるパターン ### 毎時のメモリ再取得(LLM エージェント向け) ```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"} }' ``` ### 定期的なチャットポーリング(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)