Laravel scheduled job did not resume after maintance mode - laravel

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

Related

Laravel not executing scheduled command

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

Laravel task scheduler permission problem with cleanDirectory command

I've set up a console command with a handle() function like this:
public function handle()
{
$fileSystem = new Filesystem;
$fileSystem->cleanDirectory('storage/app/public/tmp');
}
And in the console kernel I set up the command:
$schedule->command('cleanupfiles:tmp')
->everyMinute()
->sendOutputTo(storage_path('logs/taskoutput.log'));
The superuser's crontab has the following entry:
* * * * * php /var/www/website/artisan schedule:run >> /dev/null 2>&1
I can see the task scheduler getting executed every minute by looking at the /var/log/syslog, so cron does it's job, but the folder contents are not cleaned. When I run the task directly on the terminal by: php artisan schedule:run I have the same effect; no files are deleted. Finally when I run the schedule with sudo php artisan schedule:run I see it works, files get deleted and output is written to taskoutput.log.
How can I solve this so the task runs with necessary permissions? Or is there anything else I miss here? Thanks.

Running artisan command from controller or route

I use Spatie Laravel package I can take backup by running this command
php artisan backup:run
but I want to take back up form admin panel and running this command form controller, I create a route and controller and in the controller, I do this
public function backup(){
\Artisan::call('backup:run');
return "successfully!";
}
when I route to this finally I got the success message but in the backup file, nothing added.
You can put artisan command in sheduler. It will make back up for example every day at the same time. You do it in app/console/Kernel.php
$schedule->command('backup:run')->daily();
Remember to set your server for cron jobs:
* * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1
Read more: https://laravel.com/docs/5.6/scheduling

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?

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