josh088
josh088

Reputation: 121

Serialization of closure failed: The closure was not found within the abstract syntax tree

I am receiving this error in production but not in local testing:

Serialization of closure failed: The closure was not found within the abstract syntax tree.

I use Homestead/Vagrant on my local machine to ensure the environment is similar to production and I cannot track down why I started receiving this in production when I did not receive it at all in local testing.

The snippet of code is below, any thoughts are greatly appreciated.

foreach ($notifications as $notification) {
    $data = array('eventInfo' => $eventInfo, 'bowlerInfo' => $bowlerInfo, 'bowlerSchoolInfo' => $bowlerSchoolInfo,
        'matchInfo' => $match, 'notificationInfo' => $notification);

    Mail::queue('emails.matchEventAddedNotification', $data, function ($message) use ($notification, $bowlerInfo) {

        $dataHeader['category'] = 'Match Event Notification';
        $dataHeader['unique_args']['message'] = 'Email related to a new match event notification.';
        $dataHeader['unique_args']['bowler_id'] = $bowlerInfo['id'];
        $dataHeader['unique_args']['matchevents_notify_id'] = $notification['id'];
        $header = json_encode($dataHeader);
        $message->getSwiftMessage()->getHeaders()->addTextHeader('X-SMTPAPI', $header);
        $message->subject('New Score Added For' . ' ' . $bowlerInfo['first_name'] . ' ' . $bowlerInfo['last_name']);
        $message->to($notification['email']);
    });

    $matcheventNotify = Matchevent_Notify::find($notification['id']);
    $matcheventNotify->last_sent = Carbon::now();
    $matcheventNotify->save();
}

Production Environment

APP_ENV=production
APP_DEBUG=false
APP_KEY=XXXXX

DB_HOST=localhost
DB_DATABASE=klaabowling
DB_USERNAME=XXXXXXX
DB_PASSWORD=XXXXXXX

CACHE_DRIVER=file
SESSION_DRIVER=file

DOMAIN_BASE=klaabowling.com
APP_URL=http://klaabowling.com

AWS_REGION=us-west-2
AWS_AccessKey=XXXXXX
AWS_SecretAccessKey=XXXXXX

GOOGLE_MAPS_API_KEY=XXXXXX

Upvotes: 1

Views: 1694

Answers (1)

josh088
josh088

Reputation: 121

I have been able to track down the issue. The issue was the queue worker I am using in production. I am using a Daemon queue worker but I had failed to restart the queue worker so it was not recognizing my new code. Relevant information from the Laravel documentation:

php artisan queue:restart

Deploying With Daemon Queue Listeners

Upvotes: 2

Related Questions