简体   繁体   中英

Problems in Laravel using queue

I'm having some problems that until now i couldn't resolve. When i execute php artisan queue:work i have the next error:

[2019-09-22 23:25:20][12] Processing: App\Listeners\WelcomeNewStudentListener

[2019-09-22 23:25:20][12] Failed: App\Listeners\WelcomeNewStudentListener

Below my .env file:

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:i+VBlcoP1fQodPn+ZV9os2knWv/piI4Gb/TDr0Dmq9U=
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=crudAlumnos
DB_USERNAME=root
DB_PASSWORD=12345

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=database
SESSION_DRIVER=file
SESSION_LIFETIME=120

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_ENCRYPTION=null

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

In my EventServiceProvider.php i have the next:

<?php

    namespace App\Providers;

    use App\Events\NewStudentHasRegisteredEvent;
    //use App\Listeners\WelcomeNewStudentListener;
    use App\Listeners\RegisterStudentToNewsletter;
    //use App\Listeners\NotifyAdminViaSlack;
    use Illuminate\Support\Facades\Event;
    use Illuminate\Auth\Events\Registered;
    use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
    use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;

    class EventServiceProvider extends ServiceProvider
    {
        /**
         * The event listener mappings for the application.
         *
         * @var array
         */
        protected $listen = [
            //agregando mi evento
            NewStudentHasRegisteredEvent::class => [
                //aqui se agrega el listener
                \App\Listeners\WelcomeNewStudentListener::class,
                RegisterStudentToNewsletter::class,
                \App\Listeners\NotifyAdminViaSlack::class,
            ],
        ];

        /**
         * Register any events for your application.
         *
         * @return void
         */
        public function boot()
        {
            parent::boot();

            //
        }
    }

And finally in my WelcomeNewStudenListener.php

<?php

namespace App\Listeners;

use App\Mail\WelcomeNewUserMail;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Mail;

class WelcomeNewStudentListener implements ShouldQueue
{

//ESTE ES EL LISTENER
    /**
     * Handle the event.
     *
     * @param  object  $event
     * @return void
     */
    public function handle($event)
    {
        //
        sleep(10); //10 seconds

        Mail::to($event->datosEnviar->email)->send(new WelcomeNewUserMail());
    }
}

Additionaly i have the jobs and the failed_jobs tables on my database.

So I haven't been able to solve that problem with queue:work

please add this code in your env file. in mailtrap.io website SMTP setting add this user name and password in your env file

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=***********(your username)
MAIL_PASSWORD=**********(your password)
MAIL_ENCRYPTION=tls

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM