I created my Command and registered at the service provider $command variable from my module, but how I schedule it? Normally I will put it at the Kernel.php file inside Console folder. But how to do it if I want a different schedule for each module? Something like Kernel.php inside of each module but I don't really know how to do that.
I haven't done this before, but you can schedule each command individually so you can do it that way.
If it's a fixed schedule par module you can develop something to handle this automatically
use Illuminate\Support\ServiceProvider;
use Illuminate\Console\Scheduling\Schedule;
class ScheduleServiceProvider extends ServiceProvider
{
public function boot()
{
$this->app->booted(function () {
$schedule = $this->app->make(Schedule::class);
$schedule->command('some:command')->everyMinute();
});
}
public function register()
{
}
}
Then in module.json register your schedule service provider
{
"name": "Module",
"alias": "module",
"description": "",
"keywords": [],
"active": 1,
"order": 0,
"providers": [
"Module\\Providers\\ResourceServiceProvider",
"Module\\Providers\\EventServiceProvider",
"Module\\Providers\\ScheduleServiceProvider"
],
"aliases": {},
"files": [],
"requires": []
}
Most helpful comment
Then in module.json register your schedule service provider