简体   繁体   English

Laravel Iron Queue :: push似乎不是异步的

[英]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). 我有一个表单,允许用户输入一些文本并上传图像(然后调整图像大小并发送到TinyPNG.com进行优化)。 Upon clicking on the submit button the form sends data via JQuery AJAX. 单击提交按钮后,表单通过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. 在数据发布完成后,我想通过AJAX函数中的On Success向用户显示一些消息,但不等待图像处理过程。 To do this, I created a Laravel Queue with Iron, with the code below: 为此,我使用Iron创建了一个Laravel队列,代码如下:

\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). 总体来说一切正常,除了AJAX成功函数只在整个图像处理过程完成后触发(这需要很长时间)。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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