npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

laravel-queues

v0.3.1

Published

Create jobs for your Laravel application using JavaScript and TypeScript.

Downloads

11

Readme

Laravel JavaScript Queue

Create jobs for your Laravel application using JavaScript and TypeScript.

Install

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

Usage

Basic dispatch

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

    /**
     * Execute the job.
     */
    public function handle(): void
    {
        echo 'Pong';
    }
}
import { Queue, Job } from 'laravel-queues';

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

queue.dispatch(job);

Dispatching with data

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;
    }
}
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

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;
    }
}
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

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.

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

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

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