So I have this weird issue with mail notifications. I have deployment on Amazon Elastic Beanstalk , and I am using Amazon SQS as queueing service. For mail I am using Mailgun . Now the problem is when the mail notification is queued and processed it fails.
And here is the interesting part, when I send an email notification that is not queued, it is sent correctly, and after that the queue emails are sent as well for sometime and then again they start to fail.
I've added SerializeModels
trait to notifications as well. However it does not work until I send one email that is not queued.
My User
class has also properly implemented the method routeNotificationForMail
and is returning the user's email.
Anyone faced similar issue?
##EDIT
So I have drilled it down to where the problem is, the worker process running in systemd
is somehow unable to translate or transfer the environment variables from file /opt/elasticbeanstalk/deployment/env
. Now when I run this in terminal the queue is processing just fine. But when the queue worker is restarted nothing works.
I am using the EnvironmentFile=/opt/elasticbeanstalk/deployment/env
in my laravel_worker.service
Does anyone have any idea how I can go about this?
So after trail and error... banging my head here and there... the solution was pretty simple.
I knew the command to supply environment variables to tinker
, so I created a shell script with the following content.
#!/bin/sh
cd /var/www/html && export $(cat /opt/elasticbeanstalk/deployment/env) && php artisan queue:work
The script file was owned by the root user, so I don't have to use
sudo
withcat
Then I executed the script through systemd
service.
ExecStart=/usr/bin/nohup /var/www/html/worker_script.sh
Through .ebextenstions
files:
/var/www/html/worker_script.sh:
mode: "000755"
owner: root
content: |
#!/bin/sh
cd /var/www/html && export $(cat /opt/elasticbeanstalk/deployment/env) && php artisan queue:work
/etc/systemd/system/laravel_worker.service:
mode: "000755"
owner: root
group: root
content: |
# Laravel queue worker using systemd
# ----------------------------------
#
# /lib/systemd/system/queue.service
#
# run this command to enable service:
# systemctl enable queue.service
[Unit]
Description=Laravel queue worker
[Service]
EnvironmentFile=/opt/elasticbeanstalk/deployment/env
Restart=always
ExecStart=/usr/bin/nohup /var/www/html/worker_script.sh
[Install]
WantedBy=multi-user.target
All configuration files are available at https://github.com/stescacom/elastic_beanstalk_laravel_mongo_config Hope this helps someone else.
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.