Laravel not executing scheduled command - laravel

I'm using laravel telescope. I used the following code to schedule the prune command in kernel.php (it has 48 hours but I already tried with less hours):
$schedule->command('telescope:prune --hours=48')->daily();
I tested it in my local environment and it prunes the data correctly. But once in my production server it doesn't seem to be working.
Telescope is runing there and capturing data. I thought it could be a telescope command issue, but I ran
php artisan telescope:prune
and it works, it says "25404 entries pruned", I also verified this in the DB. Also, my cron task is runing every minute, and I have some scheduled calls like this:
$schedule->call('*some irrelevant stuff*')->cron('0 */3 * * *');
$schedule->call('*some irrelevant stuff*')->dailyAt('00:00');
And they are working as expected. I also tried calling the scheduller manually inside a function:
Artisan::call('schedule:run');
and the schedule calls work, but "$schedule->command" does not.
So, I'm guessing that the problem is that somehow "$schedule->command" is not working. Do you have any idea or suggestion to fix this?

You should set Laravel Task Scheduler to your's servers crontab file, adding the following entry:
* * * * * php /path/to/artisan schedule:run 1>> /dev/null 2>&1

Related

Laravel scheduled job did not resume after maintance mode

I did a maintanace on my laravel app by php artisan down. Then again after 15 minutes I did php artisan up.
But the scheduled jobs have not still resumed. They are not being executed as it was before.
Schedueled jobs are not being executed even when I manually give the command. ex: php artisan my:command
I think by making logs of your cronjobs will help you.
First Method
remove this part from you cronjob
>> /dev/null
Now add log file path in you cronjob
* * * * * php /var/www/html/project/artisan schedule:run >> /var/www/html/project/mylog.log 2>&1
create a log file and this file 777 (writable) permission.
so you can check what actually happening
Second Method
Or you can use method appendOutputTo() in your kernal.php
$schedule->command('inspire')->everyMinute()->appendOutputTo($filePath);
$filePath is a path of a log file you can give a public path or storage path

Laravel Schedule creates a file for every call to a command

I have created a schedule with Laravel and after some struggle I managed to get it working but the problem now is that for every call to the a command it creates a file inside the laravel folder and they are getting pilled up.
I am using this command at the crontab to keep it running:
* * * * * /usr/local/bin/php path/to/artisan schedule:run >> /dev/null 2>&1
I guess I need to use some options to prevent it from output. Any idea?

Does task scheduling in Lumen work just like in Laravel?

You can see task scheduling explained in the latest docs for Laravel, but Lumen's docs do not mention this. However, it looks like Lumen's Console Kernel file has a schedule method just like Laravel. Does scheduling work the same in both, or what are the caveats with scheduling in Lumen?
Yes, yes it does! :) It works exactly the same.
crontab -e
And then add
* * * * * php /var/www/domain.com/public_html/artisan schedule:run 1>> /dev/null 2>&1
Come to think of it, the php artisan schedule:run kinda gives it away :p

Laravel command in cronjob will not executed correctly

I've edited the crontab (centos) like this:
0 6 * * * php /var/www/site/artisan eex --update=true
The crontab (/var/log/cron) shows that the command has been executed successfully:
Dec 10 06:00:01 yyy CROND[19946]: (user) CMD (php /var/www/site/artisan eex --update=true)
However, the database has not been updated. If I start the command manually, it works fine:
[user#yyy energiems]$ php /var/www/site/artisan eex --update=true
> Updated 1 element(s) (43f70960-772c-11e4-92a4-57928d74f84f)
(...)
> Updated 1 element(s) (43fd1470-772c-11e4-b1f2-b58d1e3307a3)
Any ideas?
//edit: In addition to Dwights answer, I also noticed, that the cronjob runs in the wrong timezone. I've adjusted it to Germany and it works fine now.
Find out where the location of php is on your server with the which php command.
Then, update your crontab to reference php at it's precise location.
Odd solution I know, but I had a similar issue and this turned out to be the fix.

Laravel4 task to cron

I'm trying to create a cron using a task I made. The problem is I have no clue how to build the cron. My task name is meeting:close, and it's in my commands folder.
Can anyone help me to build the url to call this task every hour? I guess it will start with 0 * * * *
Thanks everyone!
To create a cronjob, you have to edit a file. It is pretty easy, run crontab -e to edit the cron file for the current user.
Now just add a line to the file that opens:
0 * * * * php /full/path/to/your/application/artisan meeting:close
Maybe you also have to specify the absolute path to your php executable
Now save the file and you're all set.
By the way, if you didn't know, you can run your commands with php artisan command:name from the terminal (that's also what the cronjob is going to do...)

Resources