问题
So, as far as I understand, commands are now jobs in Laravel 5.1. If I'd like to schedule a job, should I call a job from a command then (since the scheduler can only call commands and not jobs)?
In the dummy setup of Laravel 5.1 there still is a app/Console/Commands folder with Inspire.php in it. The inspire command is called from the scheduler. So if I'd like to schedule a job, should I call a command and then call the job inside this command?
回答1:
Commands are not jobs. Commands are commands - you can create them and use them via command line. They can, however, be used for scheduling repeated tasks.
In this case - if you need a "job" - the documentation states:
The only Cron entry you need to add to your server is this:
- php /path/to/artisan schedule:run 1>> /dev/null 2>&1
After you did that, you are free to use the implementation explained here. Basically, you use the Scheduler to set tasks that will run in whatever iterations you like. Pretty cool, isn't it?
来源:https://stackoverflow.com/questions/31995183/laravel-5-1-commands-and-jobs