Skip to main content

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

job_id
string
required
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)

status
string
Job state: pending, running, completed, failed, or merged
branch
string
Git branch name (job/{job_id})
pr_url
string
GitHub pull request URL (available after job completion)
run_url
string
GitHub Actions run URL
log
string
Job execution log (available after completion)
changed_files
array
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

StateDescription
pendingJob created, waiting for GitHub Actions to start
runningDocker agent container is executing the task
completedJob finished, PR created with results
failedJob encountered an error during execution
mergedPR was auto-merged into main branch

Implementation

Calls getJobStatus(jobId) from lib/tools/github.js, which:
  1. Fetches branch details from GitHub API
  2. Checks for associated pull request
  3. Fetches workflow run status
  4. 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.

Build docs developers (and LLMs) love