Could you provide more content, maybe the job class you want run?
Queue Worker in Forge gives error, but not if done manually.
Since we are scaling up our operations by about 5x in January I wanted to take server management off my plate and set up Forge last night.
All went according to plan, except people can no longer receive queued emails or sms messages. a little bit of digging in the logs shows that the queue worker I set up in forge is tossing this error on every job:
[2020-12-11 17:46:45] production.ERROR: Trying to access array offset on value of type null {"exception":"[object] (ErrorException(code: 0): Trying to access array offset on value of type null at /home/forge/EXAMPLE.COM/vendor/laravel/framework/src/Illuminate/Queue/QueueManager.php:156)
[stacktrace]
#0 /home/forge/EXAMPLE.COM/vendor/laravel/framework/src/Illuminate/Queue/QueueManager.php(156): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError()
...
}
After doing a bit of investigation I noticed that the culprit appears to be the connection name, I provided mysql since that's the name of my database connection and in .env my QUEUE_DRIVER is set to database. Doing so generates a worker config like this:
[program:worker-326584]
command=php7.4 /home/forge/EXAMPLE.COM/artisan queue:listen mysql --sleep=10 --quiet --delay=5 --tries=3 --queue="default"
process_name=%(program_name)s_%(process_num)02d
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=forge
numprocs=2
stdout_logfile=/home/forge/.forge/worker-326584.log
It was confusing me because if I ran the queue in the terminal (without connection name) it ran with no issues, so I added my own queue worker config to /etc/supervisor/conf.d and it is running fine... However, I want to be able to manage these in Forge if possible.
My queue worker (that works) looks like this:
[program:worker-ns4]
command=php7.4 /home/forge/EXAMPLE.COM/artisan queue:listen --sleep=10 --quiet --delay=5 --tries=3 --queue="default"
process_name=%(program_name)s_%(process_num)02d
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=forge
numprocs=2
stdout_logfile=/home/forge/.forge/worker-ns4.log
So what gives? They are virtually the same, except mine omits the connection name that forge is forcing me to provide.
Any ideas how I can get this to work in Forge?
I figured it out after testing a bit on a separate server.
Turns out connection needs to correlate to an index in the connections database in config/queue.php and not the database driver you are using.
Since I was listing "mysql" instead of "database", it was unable to find that connection. Which seems pretty obvious now.
I ended up at this solution after reading the forge docs, which directed me to the queue docs, which makes mention of it needing to correlate to an option in the config file. Would have been nice to have an option to omit the connection (see above how my worker works fine without it) or have the default options in a drop down with the ability to type in custom ones. Oh well, that is neither here nor there.
Hope this helps someone else that may have overlooked this.
Please or to participate in this conversation.