Laravel Cron Job not running over ubuntu server - laravel

I have a laravel application setup over Ubuntu server using Nginx. Here I have the cron jobs. I was facing an issue, that the server was not automatically picking up changes on Jobs Files. So I googled the things, and found a command from this article which I ran;
php artisan queue:restart
Since I have run this command, now no job is running even. I am also trying with simple HeartbeatJob to log info but it is also not working. When I do php artisan schedule:run,
no error in particular just screen output as:
[2021-09-11T08:41:32+00:00] Running scheduled command: App\Jobs\Heartbeat
But nothing happens. Any idea what this queue command has done wrong and how I make my jobs working again?

Your cron job will need the absolute path to artisan, so should look something like :
php /home/user/site.com/artisan queue:restart
You may also need to specify the queue with :
php /home/user/site.com/artisan queue:restart --queue=nameofqueue

Related

Laravel Queue queue:work running in background in Shared hosting(CPanel)

In my project, I've made a simple newsletter system where I want to send an email to all subscribers. But the problem I faced in production (Cpanel hosting) I have to run laravel queue:work command in terminal. Can anyone tell me how to handle queue:work in background in CPanel hosting...
can anyone tell me how to handle this problem?
For sending the mail I'm using the cpanel mail smtp not using any other third party like mailchimp or mailgun etc...
**find crob job tab into your cpanel then set the cron job **
like
daily
after 5minutes or whatever you want
make a job to handle the user news letters like
php artisan make:job UserNewsLetters
and then make a email
php artisan make:mail NewsLetterEmail
make a view into mail/newsletter
access the mailabel into your job set cron job path to your project folder like this /usr/local/bin/php /home/hosting_user/public_html/artisan queue:work or you can utilize laravel console commands https://laravel.com/docs/8.x/scheduling
please check this image and set cron job not run commandline
add this command into your cron task with full php path
php /path/to/laravel/artisan queue:work --stop-when-empty
to check php path run this in commandline
which php
cron task have these options to run your job
1-once per minute (mean job only run once in one minute so once per minute mean it will run 60 times in One Hour)
2-Every day mean once in 24hr
3- weekly job run once in a week
you can also make console commands for schedule your task and laravel have clear documentation Task Scheduling

Laravel job work command not working as before

My application's job - queue was working smoothly. Supervisor was also works fine before. But in last couple of day this jobs are not processing as before..
No error and nothing on logs file [Edited]
Queue driver set on Database
QUEUE_DRIVER=database
also tried QUEUE_DRIVER=sync
So, I've tried manual work command in vps. Although same code's working on local machine and my test-server And as you can see.. Nothing appears
also tried other commands
php artisan queue:work --queue=default --tries=1

laravel vapor schedule job not running as scheduled

I have setup a laravel vapor as per documentation. Everything is working fine except scheduler.
I have set few artisan commands at certain intervals. But commands are not running as per schedule. If i run command manually it works. Seems like artisan schedule:run is not running and hence commands are not fired on defined time.
I checked lamda cli logs, no errors found. What do i check?
I fixed the issue adding below line in vapor.yml
scheduler: true
This was happening to me but in my case it was solved by composer dump-autoload.

Laravel 5.3 queue worker, stop after some time through Jenkins

In Laravel 5.3.
I'm running through jenkin a command of laravel:
php artisan queue:work
But I need to stop it. Ideally I would like to stop the worker after the queue jobs gets empty, but it's not possible on Laravel 5.3. So another option would be to stop the command after sometime, let's say 1 minute.
How can I stop a process running through jenkins after some time? or stop a php artisan command.
With php artisan queue:restart I can stop all the jobs so I tried:
php artisan queue:work
sleep 60; php artisan queue:restart
But that 2nd line will never get reached because the workers is still running.
Any tip?
you can use some solution form solve it
1.
You save server resources by avoiding booting up the whole app on
every job.
You have to manually restart the worker to reflect any
code change you made in your application.
You can also run:
php artisan queue:work --once
2- This will start an instance of the application, process a single job, and then kill the script.
php artisan queue:listen
The queue:listen command simply runs the queue:work --once command inside an infinite loop, this will cause the following:
An instance of the app is booted up on every loop.
The assigned worker will pick a single job and execute it.
The worker process will be killed.
Using queue:listen ensures that a new instance of the app is created for every job, that means you don't have to manually restart the worker in case you made changes to your code, but also means more server resources will be consumed.

Laravel php artisan serve logs stored and start artisan serve automatically

id like to know :
Where Laravel php artisan serve command logs stored ?
How to automatically start php artisan serve when sever (Apache) starts ?
Laravel logs are stored at storage/logs
You don't need artisan serve, if you have Apache handling your HTTP traffic.
To the first question
Where Laravel php artisan serve command logs stored ?
Laravel server logs are stored in storage/logs folder ,which contains files for the server logs
To the second question
How to automatically start php artisan serve when sever (Apache) starts ?
If you need to automatically ,A very simple way to do this would be to use use laravel scheduling Artisan Commands using cron
Ensure cron is installed yum install vixie-cron (assuming you use centos). Start it with service crond start
Add laravel Schedule object vi /etc/crontab and add * * * * * php /path/to/artisan schedule:run 1>> /dev/null 2>&1 ,to the cron schedule file .
Go to app/Console/Kernel.php file and add $schedule->command('foo')->withoutOverlapping(); where foo is the artisan command you would like to run in this case serve , so it should be $schedule->command('serve')->withoutOverlapping();
Restart cron deamon with service crond restart.
See this related question https://stackoverflow.com/a/34096590/1226748
I would definitely recommend NOT using artisan's server in production like EVER, it's for testing only. -- You would be WAY better off to use nginx as a reverse proxy and you can set whatever port you want that way, and have your angular app still connect to it.

Resources