HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux ip-172-31-42-149 5.15.0-1084-aws #91~20.04.1-Ubuntu SMP Fri May 2 07:00:04 UTC 2025 aarch64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/vhost/disk-apps/alq-cali.bikenow.co/app/Jobs/Clients/GenerateClientExportJob.php
<?php
// app/Jobs/Clients/GenerateClientExportJob.php

namespace App\Jobs\Clients;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Maatwebsite\Excel\Facades\Excel;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Storage;
use App\Http\Controllers\Exports\ClientsExport;
use App\Core\Customer\CustomerTableService;
use Illuminate\Http\Request;

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

    public $timeout = 3600;
    public $tries = 3;
    
    protected $requestData;
    protected $filename;
    protected $userId;

    public function __construct($requestData, $filename, $userId)
    {
        $this->requestData = $requestData;
        $this->filename = $filename;
        $this->userId = $userId;
    }

    public function handle(CustomerTableService $customerTableService)
    {
        try {
            $request = new Request($this->requestData);
            
            $report = (new ClientsExport())->setQuery(
                $customerTableService->getTableQuery($request)
            );

            Excel::store($report, $this->filename, 'public');
            
            Cache::put("export_{$this->userId}_{$this->filename}", [
                'status' => 'completed',
                'filename' => $this->filename,
                'url' => asset('storage/' . $this->filename),
            ], now()->addHours(24));

        } catch (\Exception $e) {
            logger()->error('Error generando export de clientes', [
                'error' => $e->getMessage(),
                'trace' => $e->getTraceAsString(),
                'filename' => $this->filename,
                'user_id' => $this->userId
            ]);
            
            Cache::put("export_{$this->userId}_{$this->filename}", [
                'status' => 'failed',
                'error' => 'Error al generar el archivo. Por favor intente nuevamente.'
            ], now()->addHours(1));
            
            throw $e;
        }
    }
}