vendredi 3 avril 2015

Laravel 5 - Queued Command throwing errors in handle()


Vote count:

0




I am trying to make a queued command that collects a listing of recipients and sends an email. The command has four methods - the constructor, handle(), getRecipients(), and sendEmail().


After the constructor does its thing, the handle() method should be called. In turn it should trigger getRecipients() which, when complete, should sendEmail(). I have found that if I place getRecipients() inside the handle() method, it is never called. If I place it in the constructor, it works fine.


I also noticed these errors in production:



exception 'ErrorException' with message 'unserialize(): Function spl_autoload_call() hasn't defined the class it was called for'
in /home/forge/default/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php:36

exception 'ErrorException' with message 'Error while sending STMT_PREPARE packet. PID=13191'
in /home/forge/default/vendor/laravel/framework/src/Illuminate/Database/Connection.php:358


Here is my code, some attributes and code omitted for space:



<?php namespace App\Commands;

use App\Commands\Command;

use App\User;
use Log;
use Mail;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Bus\SelfHandling;
use Illuminate\Contracts\Queue\ShouldBeQueued;

/**
* Class SendGroupEmail
* @package App\Commands
*/
class SendGroupEmail extends Command implements SelfHandling, ShouldBeQueued {

use InteractsWithQueue, SerializesModels;



/**
* Create a new command instance.
*
* @param User $user
* @param $allActive
* @param array $groupRecipients
* @param array $agencyRecipients
* @param string $subject
* @param string $message
* @param null $attachment
*/
public function __construct(User $user, $allActive, array $groupRecipients, array $agencyRecipients, $subject, $message, $attachment = null)
{
$this->user = $user;
$this->subject = trim(ucwords($subject));
$this->message = $message;
$this->attachment = $attachment;
$this->groupRecipients = $groupRecipients;
$this->agencyRecipients = $agencyRecipients;
$this->allActive = $allActive;
}

/**
* Execute the command.
*
* @return void
*/
public function handle()
{
$this->getRecipients();
}

/**
* Get Recipient Emails
*/
private function getRecipients()
{
// Get the recipients...

$this->sendEmail();
}

/**
* Send the email!
*/
private function sendEmail()
{
// Send the email....
}
}


asked 37 secs ago

NightMICU

1,616






Laravel 5 - Queued Command throwing errors in handle()

Aucun commentaire:

Enregistrer un commentaire