6

why is my queue job timing out? I am using database as a driver I tried the following:

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

yet my queue job still fails due to timeout of 60s according to the logs because the symfony process timed out. I am not using supervisor yet, just trying out how the queue works from the console

edit:: controller code + blade code controller code:

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 file:

<!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>
19
  • Perhaps your job is calling another script that is timing out due to your server's max_execution_time setting. If so, please try adding set_time_limit(1200) to the top of your processing script or long running function. Commented Oct 13, 2020 at 4:03
  • 1
    alright, will update my question details Commented Oct 13, 2020 at 4:16
  • 1
    there is a big red exclamation mark in the docs that says this in the Timeout section for queues Commented Oct 13, 2020 at 6:01
  • 1
    no worries, may not be the answer but you should make sure it is installed, good luck :) Commented Oct 13, 2020 at 6:06
  • 1
    added an answer, have a great day Commented Oct 16, 2020 at 6:52

1 Answer 1

3

If you want to be able to set the timeouts you should make sure you have the pcntl PHP extension installed and enabled.

"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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.