Skip to content
Log in

Job Management

Manage and track async jobs using the JavaScript SDK

The SDK provides methods to retrieve job status, cancel jobs, and list jobs for async operations.


Retrieve Job Status

// Start an async job
const jobResponse = await client.parse.runJob({ input: upload.file_id, settings: { model: "r-1" } });
const jobId = jobResponse.job_id;

// Retrieve job status
const job = await client.job.retrieve(jobId);

// Check status
if (job.status === "Completed") {
  console.log("Job completed!");
  const result = job.result; // ParseResponse, ExtractResponse, etc.
  if (result && 'chunks' in result.result) {
    console.log(`Found ${result.result.chunks.length} chunks`);
  }
} else if (job.status === "Pending") {
  console.log("Job still processing...");
  console.log(`Progress: ${job.progress || 0}%`);
} else if (job.status === "Failed") {
  console.log(`Job failed: ${job.reason}`);
}

Polling for Completion

async function waitForJob(client, jobId) {
  while (true) {
    const job = await client.job.retrieve(jobId);
    
    if (job.status === "Completed") {
      return job.result;
    } else if (job.status === "Failed") {
      throw new Error(`Job failed: ${job.reason}`);
    }
    
    console.log(`Status: ${job.status}, Progress: ${job.progress || 0}%`);
    await new Promise(resolve => setTimeout(resolve, 2000)); // Wait 2 seconds
  }
}

// Usage
const jobResponse = await client.parse.runJob({ input: upload.file_id, settings: { model: "r-1" } });
const result = await waitForJob(client, jobResponse.job_id);

Cancel a Job

// Cancel a running job
await client.job.cancel(jobId);

List All Jobs

// Get all jobs with pagination
const response = await client.job.getAll({
  limit: 50,
  exclude_configs: true  // Exclude raw_config to reduce response size
});

for (const job of response.jobs) {
  console.log(`${job.job_id}: ${job.status} (${job.type})`);
}

// Get next page
if (response.next_cursor) {
  const nextPage = await client.job.getAll({
    cursor: response.next_cursor,
    limit: 50
  });
}

Next Steps

Type to search…

escClose