Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Scheduled task doesn't append output to file

I'm running a scheduled task every 5 minutes, to do it I added this to schedule inside App\Console\Kernel

    

    $schedule->call(function(){   
        $this->bajarProveedores(); 
    })->everyFiveMinutes()
    ->appendOutputTo(storage_path('\logs\schedule.log'));

I've tried with backslash and forward slash for the file path and I used file_exists(storage_path('\logs\schedule.log')) to check if the file was there. The method runs without errors and it returns a string but nothing is appended to schedule.log, the method looks something like this:


    private function bajarProveedores()
    {
        try {
       // DO SOME STUFF HERE
        } catch (FileNotFoundException $exception)  {
        die('File: '.$filename.' error');
        }
        return 'File: '.$filename.' OK';

    }

I checked that file exists and I'm working on Windows with L5.1. Is this the right way to do it?

Any suggestions?

like image 740
Johan Marchan Avatar asked Nov 09 '22 10:11

Johan Marchan


1 Answers

appendoutputTo() and sendOutputTo() are exclusively for the command method and are not supported for the call method. If you would like to use these functions you will have to utilize the Command method. https://laravel.com/docs/5.1/scheduling#task-output

P.S. I am on laravel 5.8 and I still get this problem I don't think it was ever supported for call, if so I haven't figured it out.

like image 120
A. Dady Avatar answered Nov 14 '22 22:11

A. Dady