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

Why does laravel queue ignore my timeout value?

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

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);
    }
}
php artisan queue:work --timeout=1200
php artisan queue:listen --timeout=0

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

edit:: 控制器代码 + blade 代码 控制器代码:

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]);
    }
}

Blade 文件:

<!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>

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

"The pcntl PHP extension must be installed in order to specify job timeouts."

Laravel 8.x Docs - Queues - Dispatching Jobs - Specifying Max Job Attempts / Timeout Values - Timeout