Sync Laravel queue with Python. Provides an interface for communication between Laravel and Python.
MIT License
Queue sync between Python and Laravel using Redis driver. You can process jobs dispatched from Laravel in Python.
NOTE: This package is in beta and only Redis is supported currently. Production usage is not recommended until stable release.
In the 1.0.0 stable version these implementations are planned:
pip install python-laravel-queue
from python_laravel_queue import Queue as PlQueue
from redis import Redis
r = Redis(host='localhost', port=6379, db=0)
queue_python = PlQueue(r, queue='python')
@queue_python.handler
def handle(data):
name = data['name'] # job name
data = data['data'] # job data
print('TEST: ' + data['a'] + ' ' + data['b'] + ' ' + data['c'])
queue_python.listen()
<?php
$job = new \App\Jobs\TestJob('hi','send to','python');
dispatch($job)->onQueue('python');
from python_laravel_queue import Queue as PlQueue
from redis import Redis
r = Redis(host='localhost', port=6379, db=0)
queue_laravel = PlQueue(r, queue='laravel')
queue_laravel.push('App\\Jobs\\TestJob', {'a': 'hello', 'b': 'send to', 'c': 'laravel'})
TestJob in Laravel:
<?php
namespace App\Jobs;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
class TestJob extends Job implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $a, $b, $c;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct ($a, $b, $c) {
$this->a = $a;
$this->b = $b;
$this->c = $c;
}
public function handle () {
Log::info('TEST: ' . $this->a . ' '. $this->b . ' ' . $this->c);
}
}
php artisan queue:listen --queue=laravel