# laravel-queues

> Create jobs for your Laravel application using JavaScript and TypeScript.

Latest version **0.3.1** (published 2023-08-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install laravel-queues
pnpm add laravel-queues
yarn add laravel-queues
bun add laravel-queues
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.1 |
| Published | 2023-08-01 |
| First published | 2023-07-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 5 |
| Unpacked size | 43.2 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Sebastiaan "Kyzegs" Zegers |
| Maintainers | kyzegs |
| Keywords | laravel, queue, redis |

## Links

- npm: https://www.npmjs.com/package/laravel-queues
- Repository: https://github.com/Kyzegs/laravel-queues
- Homepage: https://github.com/Kyzegs/laravel-queues#readme
- Issues: https://github.com/Kyzegs/laravel-queues/issues
- npm.io page: https://npm.io/package/laravel-queues

## Dependencies (5)

- [uuid](https://npm.io/package/uuid.md) ^9.0.0
- [redis](https://npm.io/package/redis.md) ^4.6.7
- [typeorm](https://npm.io/package/typeorm.md) ^0.3.17
- [php-serialize](https://npm.io/package/php-serialize.md) ^4.1.1
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ^0.1.13

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 0.3.1 (latest) — 2023-08-01
- 0.3.0 — 2023-07-31
- 0.2.2 — 2023-07-31
- 0.2.1 — 2023-07-22
- 0.2.0 — 2023-07-22
- 0.1.0 — 2023-07-22

## README

# Laravel JavaScript Queue

Create jobs for your Laravel application using JavaScript and TypeScript.

## Install

```bash
npm install laravel-queues # npm
yarn add laravel-queues # Yarn
pnpm add laravel-queues # pnpm
```

## Usage

### Basic dispatch

```php
class Ping implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * Execute the job.
     */
    public function handle(): void
    {
        echo 'Pong';
    }
}
```

```ts
import { Queue, Job } from 'laravel-queues';

const queue = new Queue();
const job = new Job({
    name: 'Ping',
});

queue.dispatch(job);
```

### Dispatching with data

```php
class Country implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * Create a new job instance.
     */
    public function __construct(
        public string $country,
    ) {}

    /**
     * Execute the job.
     */
    public function handle(): void
    {
        // Do something with the country code
        echo $this->country;
    }
}
```

```ts
import { Queue, Job } from 'laravel-queues';

const queue = new Queue();
const job = new Job({
    name: 'Country',
    data: {
        country: 'NL',
    },
});

queue.dispatch(job);
```

### Dispatching with model

```php
class AssignRole implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * Create a new job instance.
     */
    public function __construct(
        public Role $role,
    ) {}

    /**
     * Execute the job.
     */
    public function handle(): void
    {
        // Give role to user
        echo $this->role;
    }
}
```

```ts
import { Queue, Job, Model } from 'laravel-queues';

const queue = new Queue();
const job = new Job({
    name: 'AssignRole',
    data: {
        role: new Model({
            class: 'Spatie\\Permission\\Models\\Role',
            id: 1,
        }),
    },
});

queue.dispatch(job);
```

### Connection options for driver

```ts
import { Queue } from 'laravel-queues';

const queue = new Queue({
    driver: {
        type: 'redis',
        options: {
            socket: {
                host: '127.0.0.1',
                port: 6379,
            },
        },
    },
});
```

### Database driver

Ensure that you have the `jobs` table in your database to make use of the database driver. You can create a migration for the jobs table by running the `php artisan queue:table` command.

You'll also be required to install another dependency depending on the database you're using. For example, if you're using MySQL, you'll need to install the `mysql2` package. You can find a full rundown of the required dependencies for your database driver [here](https://typeorm.io/#installation).

> ℹ️ You only have to follow step 4 of the installation guide. The other steps are already done for you.

```ts
import { Queue } from 'laravel-queues';

const queue = new Queue({
    driver: {
        type: 'database',
        options: {
            type: 'mysql',
            host: 'localhost',
            port: 3306,
            database: 'laravel',
            username: 'root',
        },
    },
});
```

### Different namespace

```ts
const job = new Job({
    name: 'Ping',
    namespace: 'App\\Jobs\\Nested\\Deeper'
});
```

---
_Source: https://npm.io/package/laravel-queues · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
