![](/img/trans.png)
[英]Iron.io Push Queue and Laravel 4 - preventing the queue request from running multiple times
[英]Laravel Iron Queue::push doesn't seem asynchronous
我有一個表單,允許用戶輸入一些文本並上傳圖像(然后調整圖像大小並發送到TinyPNG.com進行優化)。 單擊提交按鈕后,表單通過JQuery AJAX發送數據。 在數據發布完成后,我想通過AJAX函數中的On Success向用戶顯示一些消息,但不等待圖像處理過程。 為此,我使用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']]);
總體來說一切正常,除了AJAX成功函數只在整個圖像處理過程完成后觸發(這需要很長時間)。
下面是我的隊列配置文件。 如果您希望我包含任何其他代碼,請告訴我們。 提前致謝
<?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.