Skip to main content
You can programmatically execute and manage batch jobs using the Blaxel API and TypeScript SDK.
The code examples in this section assume that your batch job has already been successfully deployed on Blaxel.

Dispatch job execution

Dispatch a job and wait for execution to start:
import { blJob } from "@blaxel/core";

const job = blJob("my-job");
const executionId = await job.createExecution({
  tasks: [{ duration: 60 }]
});
const result = await job.waitForExecution(executionId);
Time units in the TypeScript SDK are specified in milliseconds.

Dispatch job execution with tasks

Dispatch a new job with tasks:
const executionId = await job.createExecution({
  tasks: [
    { duration: 30 },
    { duration: 60 },
  ]
});

Get execution details

Get full execution details:
const execution = await job.getExecution(executionId);
console.log(execution.status, execution.metadata);

Get status

The possible job states are:
pending → running → completed
                 ↘ failed
Get only the job status (faster than retrieving full execution details):
const status = await job.getExecutionStatus(executionId);
// Returns: "pending" | "running" | "completed" | "failed"

List executions

List all executions for a job:
const executions = await job.listExecutions();
console.log(`Found ${executions.length} executions`);

Wait for completion

Poll until execution completes:
const result = await job.waitForExecution(executionId, {
  maxWait: 300000,  // 5 minutes (milliseconds)
  interval: 2000,   // Poll every 2 seconds (milliseconds)
});
When polling:
  • adjust the interval based on the expected task duration
  • set the maxWait timeout longer than the expected total task duration

Complete example

Here is a complete example:
import { blJob } from "@blaxel/core";

const job = blJob("data-processing");

// create execution
const executionId = await job.createExecution({
  tasks: [{"name": "John"}, {"name": "Jane"}]
});

// monitor
let status = await job.getExecutionStatus(executionId);
console.log(`Status: ${status}`);

// wait
try {
  const result = await job.waitForExecution(executionId, {
    maxWait: 180000,
    interval: 5000,
  });
  console.log(`Completed: ${result.status}`);
} catch (error) {
  console.log(`Timeout: ${error.message}`);
}

Deploy a job

Learn how to deploy your AI batch jobs on Blaxel as a serverless auto-scalable endpoint.