Laravel任务调度 - 制作多个命令和任务

时间:2017-11-23 12:14:26

标签: cron laravel-5.3

我正在尝试制作2个工匠命令,每个命令都会执行不同的任务,这些任务也应安排在每天完成任务。 到目前为止,我已经设置了这样:

我在Console / Commands目录中创建了一个FolderImport类:

class FolderImport extends Command
{

  protected $signature = 'import:folders';

  /**
  * The console command description.
  *
  * @var string
  */
  protected $description = 'Imports folders';

  /**
  * Create a new command instance.
  *
  * @return void
  */
  public function __construct(ImportController $folders)
  {
      parent::__construct();

      $this->folders = $folders;
  }

  /**
  * Execute the console command.
  *
  * @return mixed
  */
  public function handle()
  {
      $this->folders->scheduledImport();
  }

}

ContentImport类:

class ContentImport extends Command
{
  protected $signature = 'import:content';

  /**
  * The console command description.
  *
  * @var string
  */
  protected $description = 'Imports content';

  /**
  * Create a new command instance.
  *
  * @return void
  */
  public function __construct(ImportController $content)
  {
      parent::__construct();

      $this->content = $content;
  }

  /**
  * Execute the console command.
  *
  * @return mixed
  */
  public function handle()
  {
      $this->content->scheduledImport();
  }
}

然后在内核文件中我添加了这样的内容:

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        Commands\Inspire::class,
        Commands\ContentImport::class,
        Commands\FolderImport::class,
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        $schedule->command('import:content')
            ->withoutOverlapping();

        $schedule->command('import:folders')
            ->withoutOverlapping();

        $schedule->call('App\Http\Controllers\ImportController@all')
            ->dailyAt('00:00');

        $schedule->call('App\Http\Controllers\ImportController@folder')
            ->dailyAt('00:00');
    }
}

如何将import:folders命令与ImportController@folder的呼叫和import:content的呼叫连接到ImportController@all的呼叫?

0 个答案:

没有答案