4

Here is my controller action:

public function export() {

    (new ItemsExport)->queue('items.xlsx')->chain([
        new ExportItemsEmail(auth()->user()),
    ]);

    return redirect()->back()->with('success', 'File will be emailed to you once done.');
}

Super simple, we queue up the export (there are over 5k records, can be more)

class ItemsExport implements FromQuery, ShouldQueue {

    use Exportable;

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

Again nothing fancy.

Issue: Horizon fails

I get this error in horizon:

Illuminate\Queue\MaxAttemptsExceededException: Maatwebsite\Excel\Jobs\AppendQueryToSheet has been attempted too many times or run too long. The job may have previously timed out. in /home/adam/Documents/flare/vendor/laravel/framework/src/Illuminate/Queue/Worker.php:736

From the docs this is suppose to chunk it and spin up many jobs. How ever in Horizon I see 2-3 jobs go through pending like no tomorrow, then one that stays before dying because of the above error.

Am I doing this wrong?

TheWebs
  • 12,470
  • 30
  • 107
  • 211

1 Answers1

0

had the same issue on Laravel 8.6 with Excel 3.1.48, could not export large file due to timeout. In my case i also have Supervisor with many queue workers. It seems related to the issue over here (when using simultaneous queue workers). The solution that worked for me is to:

  1. Remove the ShouldQueue from the Export Class

    class ItemsExport implements FromQuery{
    
    use Exportable;
    
        public function query() {
            return Item::query();
        }
    }
    
  2. Create another Job Class and call the Export from there

      class ItemsExportJob implements ShouldQueue {
         use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
         public function handle(){
            (new ItemsExport)->store('items.xlsx');
         }
    
      }
    
  3. Call the Job Class from the Controller Class

     ItemsExportJob::dispatch();