Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to capture output from a non-command scheduled task in Laravel?

Given the following snippet:

    $schedule->call(function () {
        // echo "HELLO 123";   // nope
        // return "HELLO 123"; // also nope
    })
        ->everyMinute()
        ->sendOutputTo(storage_path('logs/cron/hello.cron.log'))
        ->emailOutputTo('[email protected]');

The scheduled task is running, the emails are being generated, but with no content. I can capture output via the $schedule->exec and $schedule->command.

Ideal end state here is, run a few internal, non-command processes within the call method and output the results into a file/email.

like image 218
Chris Avatar asked Jan 14 '16 17:01

Chris


2 Answers

I just googled the documentation of the class you are using with the words laravel scheduled output and the documentation (Just above the anchor in a red box) states:

Note: The emailOutputTo and sendOutputTo methods are exclusive to the 
command method and are not supported for call.

Hope that helps.

like image 193
bloodstix Avatar answered Nov 14 '22 22:11

bloodstix


The accepted answer got me to the solution, but for future reference:

$schedule->call(function () {
        // Do stuff

        // Report to file
        \Storage::append('logs/cron/hello.cron.log', "HELLO 123");
    })->everyMinute();
like image 43
Chris Avatar answered Nov 14 '22 23:11

Chris