mercredi 8 janvier 2020

Laravel scheduling: after hook doesn't get called

My laravel (5.8) app is located on the shared hosting in the folder app. Folder bound to the domain is public_html located next to app. I have a scheduled task like this:

$schedule->command('feed:gen sitemap')
             ->withoutOverlapping()
             ->runInBackground()
             ->dailyAt('03:00')
             ->after(function() use($schedule) {
                $schedule->exec('mv ~/app/public/Sitemap.xml ~/public_html/Sitemap.xml');
             });

that creates sitemap.xml and moves it to the website root folder. The command part works fine, sitemap.xml is created in ~/app/ folder, but after() hook doesn't get called. I am pretty sure the paths for mv command are fine. On the other hand, it is not clear in the docs how to chain multiple calls including hooks and what function calls are chainable with each other. Maybe I need to chain something else to $schedule->exec()?..

PS: feed:gen sitemap command is created in routes/console.php like

Artisan::command('feed:gen {type}', function (FeedGenerator $gen, $type) {
    // some code
})->describe('Generates feeds for site');


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire