0

I have configured Laravel queue with horizon and everything is working perfectly, but when I start exporting the file, the horizon shows completed job while it gives me empty Excel file with 6kb in cache folder.

Here's my code:

app/exports/FullReportExport.php

<?php

namespace App\Exports;

use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithChunkReading;
use Illuminate\Contracts\Queue\ShouldQueue;
use App\Models\Admin\FullReport;

class FullReportExport implements FromQuery,  WithChunkReading, ShouldQueue
{
    use Exportable;

    public function query()
    {
        return FullReport::query();
    }

    public function chunkSize(): int
    {
        return 5000;
    }
}

app\http\FullReportController.php

<?php

namespace App\Http\Controllers\Admin\Reports;

use App\Http\Controllers\Controller;
use App\Exports\FullReportExport;

class FullReportController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth');
    }
    

    public function export()
    {
        (new FullReportExport)->store('invoices.xlsx');
    }
}

worker.log

[2023-09-20 04:05:10][10] Processing: Maatwebsite\Excel\Jobs\QueueExport
[2023-09-20 04:05:10][10] Processed:  Maatwebsite\Excel\Jobs\QueueExport

laravel-worker.ini

[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=/Applications/MAMP/bin/php/php7.4.33/bin/php /Users/cairocoder/Sites/localhost/myapp/artisan queue:work redis --timeout=3600
autostart=true
autorestart=true
user=cairocoder
numprocs=8
redirect_stderr=true
stdout_logfile=/Users/cairocoder/Sites/localhost/myapp/storage/logs/worker.log
3
  • In the examples , chunks works with ToModel impl. Commented Sep 20, 2023 at 5:04
  • @Mate even without chunks, it didn't work. Commented Sep 20, 2023 at 5:05
  • Maybe you could verify the plain sql executed. Commented Sep 20, 2023 at 5:07

1 Answer 1

0

I think you missed the return at the beginning of this statement

return (new FullReportExport)->store('invoices.xlsx')
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.