Endpoint
GET /api/jobs/status?job_id={id}
Fetches the current status of a job created via POST /api/create-job.
Authentication
Requires x-api-key header. See Authentication.
Query Parameters
The job ID returned from /api/create-job
Example Request
curl -H "x-api-key: your-api-key-here" \
"https://your-domain.com/api/jobs/status?job_id=abc12345"
Response
Success (200)
Job state: pending, running, completed, failed, or merged
Git branch name (job/{job_id})
GitHub pull request URL (available after job completion)
Job execution log (available after completion)
List of files modified by the job
{
"status": "completed",
"branch": "job/abc12345",
"pr_url": "https://github.com/owner/repo/pull/42",
"run_url": "https://github.com/owner/repo/actions/runs/123456",
"log": "Job completed successfully...",
"changed_files": ["reports/daily-2024-03-05.md"]
}
Error Responses
Unauthorized (401)
{
"error": "Unauthorized"
}
Internal Error (500)
{
"error": "Failed to get job status"
}
Job States
| State | Description |
|---|
pending | Job created, waiting for GitHub Actions to start |
running | Docker agent container is executing the task |
completed | Job finished, PR created with results |
failed | Job encountered an error during execution |
merged | PR was auto-merged into main branch |
Implementation
Calls getJobStatus(jobId) from lib/tools/github.js, which:
- Fetches branch details from GitHub API
- Checks for associated pull request
- Fetches workflow run status
- Returns aggregated status object
async function handleJobStatus(request) {
try {
const url = new URL(request.url);
const jobId = url.searchParams.get('job_id');
const result = await getJobStatus(jobId);
return Response.json(result);
} catch (err) {
console.error('Failed to get job status:', err);
return Response.json({ error: 'Failed to get job status' }, { status: 500 });
}
}
Polling for Completion
Jobs typically complete within minutes to hours depending on task complexity. Poll this endpoint to track progress:
async function waitForJob(jobId) {
while (true) {
const response = await fetch(
`https://your-domain.com/api/jobs/status?job_id=${jobId}`,
{ headers: { 'x-api-key': apiKey } }
);
const { status } = await response.json();
if (status === 'completed' || status === 'failed' || status === 'merged') {
return status;
}
await new Promise(resolve => setTimeout(resolve, 30000)); // Poll every 30s
}
}
Alternative: Webhook Notifications
Instead of polling, configure GitHub webhooks to receive notifications when jobs complete.