# General Translation Platform: awaitJobs
URL: https://generaltranslation.com/en-GB/docs/platform/core/reference/gt-class-methods/translation/await-jobs.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: Poll queued translation jobs until they complete, fail or time out. API reference for awaitJobs.

Waits until every job is `completed`, `failed` or `unknown`, or the timeout is reached. Supports translation and setup jobs.

## Overview [#overview]

Pass the result of [`enqueueFiles`](/docs/platform/core/reference/gt-class-methods/translation/enqueue-files) or an array of job IDs to `awaitJobs`, optionally with polling settings. It resolves with the final status of each job.

```typescript
const gt = new GT({ projectId: 'your-project-id', apiKey: 'your-api-key' });

const enqueueResult = await gt.enqueueFiles(uploadedFiles, {
  sourceLocale: 'en',
  targetLocales: ['es', 'fr'],
});

const result = await gt.awaitJobs(enqueueResult);

if (result.complete) {
  console.log('All jobs finished');
} else {
  console.log('Timed out — some jobs still in progress');
}
```

Signature:

```typescript
awaitJobs(
  jobs: EnqueueFilesResult | string[],
  options?: AwaitJobsOptions
): Promise<AwaitJobsResult>
```

*Warning: `complete: true` means all jobs reached a terminal state — it does **not** mean all jobs succeeded. Check each `job.status` to confirm success.*

## How it works [#how-it-works]

* **Automatic polling.** Replaces manual polling loops — you do not need to call [`checkJobStatus`](/docs/platform/core/reference/gt-class-methods/translation/check-job-status) in a `while` loop yourself.
* **Terminal states.** Resolves when every job is `completed`, `failed`, or `unknown`. Jobs the API cannot find are treated as `'unknown'`.
* **Deadline.** Each status request has a timeout of at most 60 seconds, shortened to the remaining overall time. At timeout, the last known statuses are returned with `complete: false`; they may still be queued, processing, or unknown. Custom fetch implementations must honour cancellation to stop promptly.
* **Errors.** Status errors before the deadline cause a rejection. Errors after the deadline return incomplete results instead. Stopping polling does not cancel remote jobs.
* **Empty input.** After validating credentials and project ID, empty input resolves with `{ complete: true, jobs: [] }`.

## Parameters [#parameters]

| Parameter             | Description                                                                                                                               | Type                                                                                                          | Optional | Default |
| --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- | -------- | ------- |
| [`jobs`](#jobs)       | The result returned by [`enqueueFiles`](/docs/platform/core/reference/gt-class-methods/translation/enqueue-files) or an array of job IDs. | [`EnqueueFilesResult`](/docs/platform/core/reference/gt-class-methods/translation/enqueue-files) | `string[]` | No       | —       |
| [`options`](#options) | Polling configuration.                                                                                                                    | `AwaitJobsOptions`                                                                                            | Yes      | —       |

### `jobs`

**Type** [`EnqueueFilesResult`](/docs/platform/core/reference/gt-class-methods/translation/enqueue-files) | `string[]` · **Required**

The result returned by [`enqueueFiles`](/docs/platform/core/reference/gt-class-methods/translation/enqueue-files), or job IDs returned by another workflow such as [`setupProject`](/docs/platform/core/reference/gt-class-methods/translation/setup-project). When you pass a queue result, its `jobData` identifies the jobs to poll.

### `options`

**Type** `AwaitJobsOptions` · **Optional**

Polling configuration from `generaltranslation/types`. Unlike the [API polling options](/docs/platform/core/reference/api-client#job-polling), class options do not expose `onPoll` or a caller signal:

| Field                    | Description                                                      | Type     | Optional | Default        |
| ------------------------ | ---------------------------------------------------------------- | -------- | -------- | -------------- |
| `pollingIntervalSeconds` | How often to poll for status updates.                            | `number` | Yes      | `5`            |
| `timeoutSeconds`         | Maximum time to wait before resolving with the current statuses. | `number` | Yes      | `600` (10 min) |

## Returns [#returns]

**Type** `Promise<AwaitJobsResult>`

Resolves to an `AwaitJobsResult` with an overall flag and the final status of each job:

```typescript
type AwaitJobsResult = {
  /** Whether all jobs reached a terminal state (not necessarily success). */
  complete: boolean;
  jobs: JobResult[];
};

type JobResult = {
  jobId: string;
  status: JobStatus;
  error?: { message: string };
};
```

| Property        | Description                                                                  | Type                                                                                                 |
| --------------- | ---------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- |
| `complete`      | `true` if no jobs are still in progress; `false` if the timeout was reached. | `boolean`                                                                                            |
| `jobs`          | Final status of each job.                                                    | `JobResult[]`                                                                                        |
| `jobs[].jobId`  | The job identifier.                                                          | `string`                                                                                             |
| `jobs[].status` | Latest status; may still be `'queued'` or `'processing'` at timeout.         | [`JobStatus`](/docs/platform/core/reference/gt-class-methods/translation/check-job-status#jobstatus) |
| `jobs[].error`  | Error details if the job failed.                                             | `{ message: string }`                                                                                |

## Examples [#examples]

Poll job IDs directly:

```typescript
const result = await gt.awaitJobs(['job-123', 'job-456']);
```

Poll the result of [`enqueueFiles`](/docs/platform/core/reference/gt-class-methods/translation/enqueue-files):

```typescript title="index.ts"
import { GT } from 'generaltranslation';

const gt = new GT({
  projectId: 'your-project-id',
  apiKey: 'your-api-key',
});

// Upload and queue
const { uploadedFiles } = await gt.uploadSourceFiles(files, {
  sourceLocale: 'en',
});

const enqueueResult = await gt.enqueueFiles(uploadedFiles, {
  sourceLocale: 'en',
  targetLocales: ['es', 'fr', 'de'],
});

// Wait for all jobs to finish (polls every 10s, times out after 5 mins)
const result = await gt.awaitJobs(enqueueResult, {
  pollingIntervalSeconds: 10,
  timeoutSeconds: 300,
});

if (!result.complete) {
  console.warn('Some jobs did not finish in time');
}

// Check individual results
for (const job of result.jobs) {
  if (job.status === 'completed') {
    console.log(`Job ${job.jobId} succeeded`);
  } else if (job.status === 'failed') {
    console.error(`Job ${job.jobId} failed: ${job.error?.message}`);
  }
}
```

## Notes [#notes]

* Jobs that are not found by the API are treated as having `'unknown'` status.
* Empty input returns `{ complete: true, jobs: [] }` after authentication validation.
* A timeout returns the last accepted statuses, which are not necessarily terminal statuses; late poll results are discarded.

## Sitemap

See the full [sitemap](https://generaltranslation.com/sitemap.md) for all pages.
