简体   繁体   中英

Laravel Iron Queue::push doesn't seem asynchronous

I have a form which allows the user to input some text and upload an image (the image is then resized and sent to TinyPNG.com for optimisation). Upon clicking on the submit button the form sends data via JQuery AJAX. I'd like to show the user some message via On Success in the AJAX function, after the data posting is complete but without waiting for the image manipulation processes. To do this, I created a Laravel Queue with Iron, with the code below:

\Queue::push('RenameClassImage',[$_POST['temp_img_id'], $class_id,$final_path,$_POST['crop_w'],$_POST['crop_h'],$_POST['crop_x'],$_POST['crop_y']]);

Overall everything works fine, except the AJAX success function only triggers AFTER the entire image manipulation process is complete (which takes a really long time).

Below is my queue config file. If you'd like me to include any other code please let me know. Thanks in advance

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Default Queue Driver
    |--------------------------------------------------------------------------
    |
    | The Laravel queue API supports a variety of back-ends via an unified
    | API, giving you convenient access to each back-end using the same
    | syntax for each one. Here you may set the default queue driver.
    |
    | Supported: "null", "sync", "database", "beanstalkd",
    |            "sqs", "iron", "redis"
    |
    */
    'connections' => [

        'sync' => [
            'driver' => 'sync',
        ],

        'database' => [
            'driver' => 'database',
            'table' => 'jobs',
            'queue' => 'default',
            'expire' => 60,
        ],

        'beanstalkd' => [
            'driver' => 'beanstalkd',
            'host'   => 'localhost',
            'queue'  => 'default',
            'ttr'    => 60,
        ],

        'sqs' => [
            'driver' => 'sqs',
            'key'    => 'your-public-key',
            'secret' => 'your-secret-key',
            'queue'  => 'your-queue-url',
            'region' => 'us-east-1',
        ],

        'iron' => [
            'driver'  => env('QUEUE_DRIVER'),
            'host'    => env('QUEUE_HOST'),
            'token'   => env('QUEUE_TOKEN'),
            'project' => env('QUEUE_PROJECT'),
            'queue'   => env('QUEUE_NAME'),
            'encrypt' => true,
        ],

        'redis' => [
            'driver' => 'redis',
            'connection' => 'default',
            'queue'  => 'default',
            'expire' => 60,
        ],

    ],

    /*
    |--------------------------------------------------------------------------
    | Failed Queue Jobs
    |--------------------------------------------------------------------------
    |
    | These options configure the behavior of failed queue job logging so you
    | can control which database and table are used to store the jobs that
    | have failed. You may change them to any database / table you wish.
    |
    */

    'failed' => [
        'database' => 'mysql', 'table' => 'failed_jobs',
    ],

];

.env文件中,您必须设置队列:

QUEUE_DRIVER=iron

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM