# Enqueuing jobs

Please read the[ introduction to tasks ](https://jamhall.gitbook.io/doddle/jobs/broken-reference)and queues before continuing with this section.

There are two options for enqueuing a job, either immediately or in the future.

### Usage

{% hint style="info" %}
Enqueuing a job immediately or in the future are functionally exactly the same with the exception of being able to pass a period into the latter.
{% endhint %}

#### Enqueuing a job immediately

This job will be executed immediately (as soon as a thread is available to process it)

```java
client.enqueue(wizard -> {
    wizard.queue("high")
          .task("sayHello");
    return wizard;
});
```

#### Enqueuing a job in the future

This job will be scheduled to be executed two minutes from now (as soon as a thread is available to process it).

```java
client.enqueueIn(wizard -> {
    wizard.period("2m")
          .queue("high")
          .task("sayHello");
    return wizard;
});
```

### Options

There are a few options you can provide when enqueuing a job. Let's explore them!

<table><thead><tr><th width="167.06666666666666">Name</th><th>Description</th></tr></thead><tbody><tr><td>name</td><td>Provide a name for your job. You can later search for jobs with this name. It does not need to be unique.</td></tr><tr><td>identifier</td><td>Provide a unique identifier for your job. This is useful if you wish to link a job to an internal identifier in your system.</td></tr><tr><td>timeout</td><td>Provide a timeout for the job. If a job exceeds the time out it will move to the failed state and be scheduled again for execution if it has not exceeded its maximum number of retries.</td></tr><tr><td>maxRetries</td><td>Set the number of max retries. If not set then it will use the default max retries set in the initial configuration.</td></tr><tr><td>arguments</td><td>Pass arguments to your job which can then be accessed during the task execution.</td></tr></tbody></table>

A full example:

```java
client.enqueue(wizard -> {
    wizard.queue("high")
          .task("payment")
          .name("process.payment")
          .identifier("order.123")
          .timeout("10m")
          .maxRetries(25)
          .arguments(
               argument("product", 123),
               // the last parameter indicates if the argument should be encrypted
               argument("creditCardNumber", "123-456-789", true)
          )
          .tags("orders", "payment");
    return wizard;
});
```
