# Worker Pool

A Queue Connection is defined inside your cbq config file using a `QueueConnectionDefinition` builder component.  You can create one of these builder components using the [`newConnection`](/2.1.0/configuration/config-file.md#newconnection) method.

### WorkerPoolDefinition Methods

#### setName

Sets the name for the Worker Pool.  Usually not called directly as the `newWorkerPool` method requires a `name`.

```cfscript
newWorkerPool( "default" )
    .setName( "not-default" );
```

#### forConnection

Sets the name of the associated Connection for the Worker Pool. This must reference an already registered Connection.

```cfscript
newConnection( "db" )
    .provider( "DBProvider@cbq" );

newWorkerPool( "db-worker" )
    .forConnection( "db" );
```

#### setConnectionName

Alias for [forConnection](#forconnection).

#### quantity

Sets the quantity of workers for this Worker Pool.

```cfscript
newWorkerPool( "default" )
    .forConnection( "db" )
    .quantity( 3 );
```

#### setQuantity

Alias for [quantity](#quantity).

#### onQueue

The name of a queue to work. The default queue is named `default`.

```cfscript
newWorkerPool( "premium-only" )
    .forConnection( "db" )
    .onQueue( "premium" );
    
newWorkerPool( "priority" )
    .forConnection( "db" )
    .onQueue( "priority" )
    .quantity( 4 );
    
newWorkerPool( "default" )
    .forConnection( "db" );
    // uses `default` queue
```

Some Providers allow for working a priority of queues, such as the `DBProvider`.  In these cases, you can pass an array of queues, in priority order, using the asterisk (`*`) as a wildcard character.

```cfscript
newWorkerPool( "premium-only" )
    .forConnection( "db" )
    .onQueue( "premium" );
    
newWorkerPool( "default" )
    .forConnection( "db" )
    .onQueue( [ "priority", "*" ] );
```

{% hint style="danger" %}
**Throws:** `cbq.WorkerPool.MultipleQueuesNotSupported`
{% endhint %}

#### setQueue

Alias for [onQueue](#onqueues).

#### backoff

Sets the backoff time amount, in seconds.

```cfscript
newWorkerPool( "default" )
    .forConnection( "db" )
    .backoff( 30 );
```

#### setBackoff

Alias for [backoff](#backoff).

#### timeout

Sets the timeout time amount, in seconds.

```cfscript
newWorkerPool( "default" )
    .forConnection( "db" )
    .timeout( 60 );
```

#### setTimeout

Alias for [timeout](#timeout).

#### maxAttempts

Sets the max number of attempts.

```cfscript
newWorkerPool( "default" )
    .forConnection( "db" )
    .maxAttempts( 5 );
```

#### setMaxAttempts

Alias for [maxAttempts](#maxattempts).


---

# 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://cbq.ortusbooks.com/2.1.0/configuration/config-file/worker-pool.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.
