I am trying to perform a job queue to execute mail and sms functioning in background process. And it is working with
QUEUE_DRIVER=sync
in .env file
But when i use it with database
QUEUE_DRIVER=database
its not working even after using cli command:
php artisan queue:listen
Please tell me what is the problem with such functionality
laravel.log:
here is how i would debug it:
stop supervisor if you are using it.
cd into your directory and type php artisan queue:listen if you see any errors then likely you have some issues with the job class that you are running laravel 5.2 give you the path in the error and if you look closely you can see in the database the parameters that were passed to the constructor.
also check to see if the reserved field in the jobs table is filled, and the attempts are more than 1.
if the attempts are 0 that means you have a problem with your supervisor service (if you are using it) try unlink /path/to/socket.sock and then run the supervisord command.
Related
I have an issue with Laravel jobs. The job is successfully registered but after being fired it does not give proper error message if there is an error. I tried to debug on my computer and that's okay. Then I run supervisor restart queue_name from worker then it works well without any changes in code. So if the error appears again, I want to restart the job but don't want to run the command from the worker. is it possible to run the command from laravel programmatically? like a command in laravel? we can run it from worker with command php artisan command_name and also run it from code(Artisan::call('command_name')). if that's possible how's the implementation?
I try to dispatch a job on my local dev machine.
I setup my .env and queue config ; QUEUE_CONNECTION=database
I also did the migrate :
php artisan queue:table
php artisan migrate
Then create my job something like : myjob::dispatchNow();
And finally run my worker: php artisan queue:work
With all that the code launch and execute well but not the job. The job is not created in the database jobs table. (nor in faield_jobs
Is I am missing any step?
Do I need something else on my local machine to run jobs queue?
Thanks for any help.
You are using synchronous dispatching by using myjob::dispatchNow(). The database does not need to be involved as it runs the job during the same request and your queue worker never knows about it. It is equivalent to having QUEUE_DRIVER=sync.
If you use myjob::dispatch() before you start the queue worker, you will see the job in your database.
I am a newbie with laravel, and I am implementing email verification system with queue in laravel.
What happening is, when I execute php artisan queue:work it works fine, when it needs to triggers, but when I quit the queue and re-execute, it doesn't trigger anymore.
I tried php artisan queue:restart, but it didn't do the trick.
What could be causing this please?
Queue will only work as long as queue:work is still running or executing in console. Any jobs fired after this has stopped will not be executed. You get to see your jobs in the database if you are using database driver as your queue driver . I use Supervisor to keep queue:work running at the backround
I'm implementing a command that will process uploaded files.
The files can contain up to 300MB of data, so the job needs to be queued and I also expect that it takes a while to complete.
My problem is, when I run php artisan queue:listen it gets the job from the queue, starts processing it normally but after around 20 seconds, it freezes. The job doesn't launch any exception and neither continues so its not removed from the queue.
I'm using the database driver. Am is missing something here?
php artisan queue:listen does not output the errors for the user. Run php artisan queue:work and it will output the errors. This command will only run one process in the queue. So you need to make sure that the next process is the one you want to debug.
Maybe it does not freezes, but it seems like it froze when you see nothing happening in command line interface after you run php artisan queue:work or php artisan queue:listen command.
As in my case,
// Execute Laravel queues by queue names on coomand line interface->
I was using running command
php artisan queue:work
which was not running my queued jobs in jobs table.
Then i relaized, it was only working for jobs with queue column value = 'default'
and i had given names like sendemail, inboxemail etc.
So when i changed this other value to 'default' in queue column in jobs table,
this job ran instantly as i have opended cli and php artisan queue:work
command was active.
So if you want to run only a specific queue by queue name, run command ->
php artisan queue:listen --queue=sendemail
or
php artisan queue:listen --queue=inboxemail
For anyone making the same mistake as I did, DO NOT CREATE TABLES BASED ON THE "JOBS" TABLE!
Its not a memory leak or sth. I had another table "job_info" with a foreign key referring to the jobs table; As it turned out laravel wasn't able to remove the job from the table after it's done successfully (as it normally do). That's because it would break the relationships in the database. So it'd keep retrying until max attempts exceeded leading to an exception with no information about the actual problem.
I now have a stable Beanstalkd and Laravel 4 Queue setup running on one machine. My question is, how can I install the Laravel 4 workers on a second machine and make them listen to my Beanstalkd? Maybe a very obvious question to some but I can't figure it out. I noticed there was a connection field in the php artisan queue:listen command. Do I have to use that?
how can I install the Laravel 4 workers on a second machine and make them listen to my Beanstalkd?
You'll need to have a working instance of your laravel application on the same server as the listener/workers.
This means deploying your application both to the web server and to server that is listening for jobs.
Then, on the listening server, you can call php artisan queue:listen in order to listen for new jobs and create a worker to handle the job.
I noticed there was a connection field in the php artisan queue:listen command. Do I have to use that?
On top of the above question, and similar to most artisan commands, you will likely also need to define which environment the queue:listen command should use:
$ php artisan queue:listen --env=production
In this way, your laravel app that is used to handle the workers (the app on the listening server) will know what configurations to use, including knowing what database credentials to use. This also likely means that both the web server and your job/listening server needs to have access to your database.
Lastly, you could also create 2 separate Laravel applications - One for your web application and one purely to handle processing job. Then they could each have their own configuration, and you'll have 2 (probably smaller?) code bases. But still, you'll have 2 code bases instead of 1.
In that regard, do whatever works best for your situation.