| title | Jobs |
|---|---|
| description | Sistema de tarefas assíncronas para operações pesadas |
Algumas coisas demoram. Baixar um vídeo, analisar com IA, processar dados pesados... Pra isso existe o sistema de Jobs.
O conceito é simples:
Ex: `POST /tiktok/download` Retorna `202 Accepted` com um `job_id` Consulta `GET /jobs/{id}` até terminar Job retorna `COMPLETED` com os dados ou `FAILED` com o erroExemplo com download de TikTok:
curl -X POST https://social-api.appconty.com/tiktok/download \
-H "X-Internal-Secret: $INTERNAL_SECRET" \
-H "X-Enterprise-Id: $ENTERPRISE_ID" \
-H "Content-Type: application/json" \
-d '{"url": "https://www.tiktok.com/@usuario/video/123"}'{
"job_id": "uuid-do-job",
"status": "PENDING",
"message": "Download job created. Poll GET /jobs/{id} for status."
}curl https://social-api.appconty.com/jobs/{job_id} \
-H "X-Internal-Secret: $INTERNAL_SECRET"{
"job_id": "uuid",
"status": "PROCESSING",
"progress": 45,
"message": "Downloading video..."
}{
"job_id": "uuid",
"status": "COMPLETED",
"result_payload": {
"post_id": "uuid-do-post",
"message": "video downloaded and saved successfully"
}
}{
"job_id": "uuid",
"status": "FAILED",
"error": {
"code": "ERR_DOWNLOAD_FAILED",
"message": "Video not accessible"
}
}| Status | O que significa |
|---|---|
PENDING |
Na fila, aguardando processamento |
PROCESSING |
Executando agora |
COMPLETED |
Terminou com sucesso |
FAILED |
Deu erro |
| Operação | Endpoint | Rate Limit |
|---|---|---|
| Download TikTok | POST /tiktok/download |
5 req/min |
| Métricas IA | POST /video/enriched-metrics |
10 req/min |
async function waitForJob(jobId) {
while (true) {
const response = await fetch(`/jobs/${jobId}`, {
headers: { 'X-Internal-Secret': SECRET }
});
const job = await response.json();
if (job.status === 'COMPLETED') {
return job.result_payload;
}
if (job.status === 'FAILED') {
throw new Error(job.error.message);
}
// Aguarda 3 segundos antes de verificar de novo
await new Promise(r => setTimeout(r, 3000));
}
}