# Adding workers

Workers are added posting a json object to the `/workers` endpoint.  An endpoint is specified as an url, which method (http verb) to use on the call to said url, which optional headers to send, as well as an optional timeout, which if reached will consider the call a failure.

```typescript
interface WorkerMetadata {
  queue: string;
  endpoint: {
    url: string;
    method: "post" | "get" | "put" | "delete" | "patch";
    headers?: Record<string, string>;
    timeout?: number; // max allowed duration in milliseconds
  }
  // .. more options
}
```

The most basic object we can send in order to start a worker could for example be the following:

{% tabs %}
{% tab title="Curl" %}

```powershell
curl --location 'http://localhost:8080/workers' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer 1234' \
--data '{
    "queue": "my-test-queue",
    "endpoint": {
        "url": "http://mydomain.dev",
        "method": "post"
    }
}'
```

{% endtab %}
{% endtabs %}

The call will return OK -200 if successful, and a worker would now be ready to start processing jobs by calling the given endpoint.&#x20;

When the endpoint is called, it will receive a JSON object with the job including its name, data and options in the body.

```typescript
interface Job {
  name: string;
  data: any;
  opts: JobOptions;
}
```

The endpoint can do its thing with the job, and when it is ready it must return a status code between 200 and 209 to signal success, and return some optional data that will be stored in the job's `returnvalue` field. If the job should be marked as fail, the call should set a status code different than 200 to 209, and return some error message that will also be stored in the job's `failedReason` field.

{% hint style="info" %}
Note that only one worker can be defined per queue. If the call is repeated for the same queue, it will just overwrite its options and restart the worker with those new options.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.bullmq.net/http-api/workers/adding-workers.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
