Tasks And Manual Triggering
目的:创建显式任务记录并触发关联的队列工作。
用户界面流程
- User defines a task payload and priority.
- UI 调用
POST /api/accounts/:account_id/tasks。 - UI shows task timeline from
/api/accounts/:account_id/tasks. - User can trigger task with
POST /api/tasks/:task_id/trigger. - UI 将任务链接到按
task_id过滤的作业列表。
客户端库流程
const task = await api.tasks.create(accountId, {
task_type: "imap_sync_messages",
target_credential_id: imapCredentialId,
payload: { folder: "INBOX" },
priority: 0,
});
await api.tasks.trigger(task.data.id);
const refreshed = await api.tasks.get(task.data.id);
HTTP/curl 流程
API_BASE_URL="https://api.inbox-manager.com"
curl -sS -X POST "${API_BASE_URL}/api/accounts/${ACCOUNT_ID}/tasks" \
-H "authorization: Bearer ${BEARER_TOKEN}" \
-H "content-type: application/json" \
--data '{
"task_type":"imap_sync_messages",
"target_credential_id":"'"${IMAP_CREDENTIAL_ID}"'",
"payload":{"folder":"INBOX"},
"priority":0
}'
curl -sS -X POST "${API_BASE_URL}/api/tasks/${TASK_ID}/trigger" \
-H "authorization: Bearer ${BEARER_TOKEN}" \
-H "content-type: application/json" \
--data '{}'
curl -sS "${API_BASE_URL}/api/accounts/${ACCOUNT_ID}/tasks?limit=20&offset=0" \
-H "authorization: Bearer ${BEARER_TOKEN}"
注释
- 提供商操作路由仍然是 IMAP/SMTP 操作的主要客户端路径。
- 通用任务对于显式队列工作流和操作工具非常有用。