> For the complete documentation index, see [llms.txt](https://cross-packages.gitbook.io/cross-api/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cross-packages.gitbook.io/cross-api/providers/queue.md).

# Queue

A queue service to run tasks in the background or schedule them to run at a certain time.

## Available:

* Bee
* Bull
* Kue
* Fake

## Jobs:

The structure is simple, it should be a class with a static `key` method to retrieve its key and a public `handle` method to perform the task. All other OOP features for distributing logic are allowed.

```typescript
export class Example {
  public static get key(): Capitalize<string> {
    return 'Example';
  }

  public async handle({ data }: { data: { message: string } }): Promise<void> {
    return console.log('I have a message for you: %s', data.message);
  }
}
```

## Methods:

**Execute:** Runs a task in the background, if it fails it repeats a certain number of times.

```typescript
await this.queueProvider.execute({
  job: Example,
  data: {
    message: 'This is the message',
  },
  attempts: 3,
});
```

**Schedule:** Schedules a task in the background, if it fails it repeats a certain number of times.

```typescript
await this.queueProvider.schedule({
  job: Example,
  data: {
    message: 'This is the message',
  },
  delay: '30min',
  attempts: 3,
});
```

**Repeat:** Schedule a background task that repeats indefinitely at the set interval.

```typescript
await this.queueProvider.schedule({
  job: Example,
  data: {
    message: 'This is the message',
  },
  interval: '30d',
  attempts: 3,
});
```

**Close:** It's used to close the connection with Redis.

```typescript
await this.queueProvider.close();
```

***
