laravel-beyond icon indicating copy to clipboard operation
laravel-beyond copied to clipboard

v7 where to put scheduled tasks

Open Wulfheart opened this issue 2 years ago • 4 comments

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).

Wulfheart avatar Aug 31 '23 18:08 Wulfheart

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

regnerisch avatar Sep 01 '23 08:09 regnerisch

This would be nice. Furthermore it would be nice to have a place to put the scheduled tasks?

Wulfheart avatar Sep 01 '23 09:09 Wulfheart

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?

alexanderkroneis avatar Oct 17 '23 08:10 alexanderkroneis

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.

alexanderkroneis avatar Dec 06 '23 14:12 alexanderkroneis

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.

regnerisch avatar Jul 21 '24 06:07 regnerisch