为什么 Laravel 队列忽略我的超时值?

Ali*_*Ali 5 php task-queue laravel laravel-8

为什么我的队列作业超时?我使用数据库作为驱动程序我尝试了以下操作:

class PdfGenerator implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected $userData;
    protected $filename;
    protected $path;
    public $timeout = 1200;
    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($userData, $filename)
    {
        //
        $this->userData = $userData;
        $this->filename = $filename;
        $this->path = \public_path('\\pdfs\\'.$this->filename.'.pdf');
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $pdf = App::make('snappy.pdf.wrapper');
        $footer = \view('supporting.footer')->render();
        $header = \view('supporting.header')->render();
        //$userData = \collect([$this->userData[1]]);
        $pdf->loadView('order_clean', ['users' => $this->userData])
        ->setOption('margin-top', '20mm')
        ->setOption('margin-bottom', '20mm')
        ->setOption('minimum-font-size', 25)
        ->setOption('header-html', $header)
        ->setOption('footer-html', $footer);
        $pdf->save($this->path);
    }
}
Run Code Online (Sandbox Code Playgroud)
php artisan queue:work --timeout=1200
Run Code Online (Sandbox Code Playgroud)
php artisan queue:listen --timeout=0
Run Code Online (Sandbox Code Playgroud)

但根据日志,由于 symfony 进程超时,我的队列作业仍然因 60 秒超时而失败。我还没有使用主管,只是尝试从控制台队列如何工作

编辑:: 控制器代码 + 刀片代码 控制器代码:

class OrderController extends Controller
{
public function renderPDF()
    {
        $user_data = $this->getUserData();
        $filename = 'test '.\now()->timestamp;
        //no timeouts here
        //if not ran on queue and with set_time_limit, takes around 70s
        //at current data size
        $this->dispatch(new PdfGenerator($user_data,$filename));
        //view returns successfully
        return \view('test.test', ['filename'=>$filename]);
    }
}
Run Code Online (Sandbox Code Playgroud)

刀片文件:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Order Layout</title>
    <style>
        *{
            font-family: cursive;
        }

        .wrapper {
            display: block;
        }

        .invoice {
            display: block;

            width: 80%;
            margin: 0 auto;
            margin-top: 10px;
            padding-top: 10px;
            padding-bottom: 10px;
            background: #d3d3d3;
            page-break-inside: avoid !important;
            padding-left: 20px;
        }

        .order-items {
            padding-left: 100px;
        }

        .table {
            width: 90%;
            align-self: center;
            border: 1px solid black;
            orphans: 15;
        }

        .table>* {
            text-align: center;
        }
    </style>
</head>

<body>

    <main class="wrapper">
        @foreach ($users as $user)

        @php
        $orders = $user->orders //just for renaming
        @endphp
        @foreach ($orders as $order)
        
        <div class="invoice">
            @php
            $sum=0;
            @endphp
            <h2>{{$user->name}}: {{$order->id}}</h2>
            <div class="order-items">
                <table class="table" border="1">
                    <thead>
                        <tr>
                            <th>Product Name</th>
                            <th>Unit Price</th>
                            <th>Qty</th>
                            <th>subtotal</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach ($order->products as $product)
                        <tr>
                            <th>
                                {{$product->name}}<br>
                                {{$product->name}}<br>
                                {{$product->name}}<br>
                                {{$product->name}}<br>
                            </th>
                            <td>{{$product->unit_price}}</td>
                            <td>{{$product->pivot->quantity}}</td>
                            @php
                            $sum+= $product->pivot->quantity*$product->unit_price
                            @endphp
                            <td>{{$product->pivot->quantity*$product->unit_price}}</td>
                        </tr>
                        @endforeach
                    </tbody>
                    <tfoot>
                        <tr>
                            <th colspan="3">Total:</th>
                            <td>{{$sum}}</td>
                        </tr>
                    </tfoot>
                </table>
            </div>
        </div>
        @endforeach
        @endforeach
    </main>
</body>

</html>
Run Code Online (Sandbox Code Playgroud)

lag*_*box 2

如果您希望能够设置超时,您应该确保已pcntl安装并启用 PHP 扩展。

pcntl必须安装 PHP 扩展才能指定作业超时。”

Laravel 8.x 文档 - 队列 - 调度作业 - 指定最大作业尝试/超时值 - 超时