dimanche 16 décembre 2018

Generated PDF attached to email fails while using JOB and Supervisor.

Hie everyone,

My scenario : I have a job which sends an email along with a pdf attached. The pdf is generated in the job handle() and attached with the email. To make user experience more friendly i used queue job for sending email. So, all the other emails works fine except when I generate a PDF:loadView. Additionally, the PDF works perfectly fine on the localhost (WAMP) However, it throws the above exception and sits in the failed_jobs table in the database.

Example of my job Class::EmailTestPdf

class EmailTestPdf implements ShouldQueue
{ 
    protected $data;
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

public function __construct(array $data)
{
    $this->data = $data;
}

public function handle()
{
    $d=$this->data;
    $d['doc'] = PDF::loadView('email.test',compact('data','survey')); 
    Mail::send('email.testpdf', $d, function ($message) use ($d)
    {
        $message->from(abc@gmail.com, 'Tester');
        $message->subject('Subject Title');
        $message->to('me@gmail.com');
        $message->attachData($d['doc']->output(), 'test.pdf', ['mime' => 'application/pdf']);
    });
}
}

On the controller method i used :

 EmailTestPdf::dispatch($data)->delay(now()->addSeconds(5));

The above works fine on localhost. However, it dosent work on the live server. Additionally, On the centOS server i implemented supervisor as below:

[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /home/coreso5/ptesting/artisan queue:work database --sleep=3 --
tries=3
autostart=true
autorestart=true
user=root
numprocs=8
redirect_stderr=true
stdout_logfile=/home/coreso5/ptesting/storage/logs/worker.log

After running a test on sending a pdf it will throw an error which I found on the failed_jobs table

ErrorException: Undefined index: SCRIPT_FILENAME in /ptesting/vendor/dompdf/dompdf/src/Css/Stylesheet.php:175

...............

Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'Undefined index...', '/ptesting/v...', 175, Array)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire