Create a scheduled task
hostware uses the default task scheduler of the Laravel Framework. Take a look at the official documentation!
It is recommended to only schedule console commands because this makes it easier for debugging in some cases. If you want to execute a function of a Helper class, please create a command and then schedule the command.
Using the scheduler, it is not needed to create a separate cronjob for each command. Learn how to register your command to the task scheduler below
Add the scheduled
To add a task to the scheduler of your module, please open the ServiceProvider class of your module in the directory /Providers/ (In this case /Providers/DashservVpsServiceProvider.php)
To prepare for task scheduling, add the following code inside of the boot() function of your ServiceProvider:
$this->callAfterResolving(Schedule::class, function (Schedule $schedule) {
});Now, you can schedule anything just like written inside of the official laravel documentation. For example, if you want to schedule a custom cli command, the function would look like this:
$this->callAfterResolving(Schedule::class, function (Schedule $schedule) {
// As you can see, we execute the command every minute. Please use
// the auto completion of your IDE or view the official documentation
// for all possible intervals.
$schedule->command('dashservvps:checkInstallingProducts')->everyMinute();
});Viewing your scheduled task
To view all the scheduled task and to check if your task was registered correctly, you can execute the following command to view all tasks:
Running the scheduler on a local environment
To run the scheduler on a local environment without cronjob, just execue the following:
Your scheduled task does not appear?
Please check that you have installed and activated your module using the hostware administration. If this still not works, please check that your module name is listed in the moduels_statuses.json file in the hostware root directory. If noot, add your module and clear the cache using php artisan cache:clear