0.5.2 • Published 6 years ago

@movilizame/noderavel v0.5.2

Weekly downloads
9
License
MIT
Repository
github
Last release
6 years ago

Noderavel

Queue sync between NodeJS and Laravel using Redis driver. You can process Jobs dispatched from Laravel in NodeJS or biceversa.

Install

npm install @movilizame/noderavel --save

Usage

  • Listen for jobs on NodeJS:
const Noderavel = require('@movilizame/noderavel');
const redis = require('redis');

redisCliente = redis.createClient(6379, 'localhost'); 

class TestJob {
    constructor(a, b) {
        this.a = a;
        this.b = b;
    }
}

let queueWorker = new Noderavel({
    client: redisCliente,
    driver: 'redis',
    scope: {
        'App\\Jobs\\TestJob': TestJob
    }
});

queueWorker.on('job', ({name, data}) => {
    console.log(name, data);
    // Proccess your jobs here.
});

queueWorker.listen();
  • Schedule a job to be run in Laravel from NodeJS:
const Noderavel = require ('@movilizame/noderavel');
const redis = require('redis');

const redisHost = 'localhost';
const redisPort = 6379;
redisCliente = redis.createClient(redisPort, redisHost); 

class TestJob {
    constructor(a, b) {
        this.a = a;
        this.b = b;
    }
}

let queueWorker = new Noderavel({
    client: redisCliente,
    driver: 'redis',
    scope: {
        'App\\Jobs\\TestJob': TestJob
    }
}); 

for (let i = 0; i < 10; i++) {
    let job = new TestJob('param1', i);
    queueWorker.redisPush('App\\Jobs\\TestJob', job);
}

TestJob in Laravel:

<?php

namespace App\Jobs; 
use Illuminate\Contracts\Queue\ShouldQueue;

class TestJob extends Job implements ShouldQueue
{
    public $a, $b;
    public function __construct ($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    function handle () {
        \Log::info('TestJob ' . $this->a . ' '. $this->b);
    }
}
0.5.2

6 years ago

0.5.1

6 years ago

0.5.0

6 years ago