laravel-beyond
laravel-beyond copied to clipboard
v7 where to put scheduled tasks
Hello,
I don't like to put my tasks in the app/Console/Kernel. Do you have any idea where I could put it instead?
Furthermore commands are not registered from modules (yet).
I don't know if we already changed the MakeCommandCommand but commands should be placed at Modules\{Module}\App\Commands\{Command}. Additional we should add a command autoloader inside the modules service provider. Something like this in the console kernel: https://github.com/laravel/laravel/blob/32ecad53a9a59d7ad33dbfd6352a5ea0fd0da2cf/app/Console/Kernel.php#L21
This would be nice. Furthermore it would be nice to have a place to put the scheduled tasks?
I think this should be in the Application layer or an individual layer and extend Illuminate\Foundation\Console\Kernel like in Laravels console kernel. By using schedule(Schedule $schedule) we'd be able to schedule tasks.
The first impulse that hit me was to structure it like this
modules
– User
–– Console
––– Kernel.php
which would introduce another layer next to Application, Domain, Infrastructure, Providers and Tests, which could bloat the individual modules since I don't think that every module will have scheduled tasks. Another approach could be to add a Console application within the Application layer and create a Kernel.php, which follows the instructions above.
@regnerisch @Wulfheart Any thoughts about this?
https://github.com/laravel/laravel/pull/6188/files#diff-c96ad2c3c018fea7d8ea9667a55e8e2fe309bc2a0df81945ab0a65493a4486f0
It seems like Command Routes are the correct place to schedule your domain specific logic.
As @alexanderkroneis mentioned, please register your commands with Artisan::registerCommand(YourCommand::class); inside routes/console.php this is considered as best practice. Your are free to extend your service provider to autoload commands. Beyond is a dev dependency and therefore has no way to load the commands in a non-dev environment.