Skip to main content

Sync Laravel queue with Python.

Project description

Python Laravel Queue

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:

  • Auto-discovery jobs in both Laravel and Python.
  • Auto-configuration by reading Laravel config in Python side.
  • More clean API.
  • Supporting more queue drivers.

Install

pip install python-laravel-queue

Usage

  • Listen for jobs on Python:
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()
  • Sending jobs from Laravel :
<?php
$job = new \App\Jobs\TestJob('hi','send to','python');
dispatch($job)->onQueue('python');
  • Schedule a job to be run in Laravel from 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);
    }
}
  • You need to :listen (or :work) the preferred queue name above to handle data sent from Python in Laravel.
php artisan queue:listen --queue=laravel

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python-laravel-queue-0.0.1b2.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

python_laravel_queue-0.0.1b2-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file python-laravel-queue-0.0.1b2.tar.gz.

File metadata

  • Download URL: python-laravel-queue-0.0.1b2.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for python-laravel-queue-0.0.1b2.tar.gz
Algorithm Hash digest
SHA256 b8d245e33a162645fac5d9ce9a84f80ebc3101dffec232d640f488731515709c
MD5 f11eb83c9ba2bc72910298ac58eb5e05
BLAKE2b-256 b9761386423e50080dbb700058cd28f08347384b0ee6a8cc968081b8d82cc086

See more details on using hashes here.

File details

Details for the file python_laravel_queue-0.0.1b2-py3-none-any.whl.

File metadata

  • Download URL: python_laravel_queue-0.0.1b2-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for python_laravel_queue-0.0.1b2-py3-none-any.whl
Algorithm Hash digest
SHA256 6ab6e95fb4eb3274d0eabdcbbff1995c46b49cb988121cf015e8e5f626fdafa4
MD5 40e9f70aeff710559c3ba03a88726659
BLAKE2b-256 39196df55217d4826b4fbee8c4c06c04bfcc34f8df01a82e294194faf57e04a6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page