LARAVEL: Get an array of scheduled tasks for output in admin dashboard

前端 未结 3 1616
深忆病人
深忆病人 2020-12-16 17:51

Using the Laravel task scheduler I have created a number of tasks in Kernel.php

e.g:

$schedule->command(\'some:command\')
    ->daily();

$sche         


        
3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-16 18:23

    I was having the task to stop/enable and edit the frequency of the scheduled tasks from the admin dashboard. So I foreach them in Kernel.php and capture the output in function.

    $enabled_commands = ConsoleCommand::where('is_enabled', 1)
            ->get();
    
        foreach ($enabled_commands as $command)
        {
            $schedule->command($command->command_name)
                ->{$command->frequency}($command->time)
                ->after(function () use ($command) {
                    $this->log($command->command_name);
                });
        }
    

    Hope this help you.

提交回复
热议问题