Pencarian

Minggu, 03 Juli 2022

Laravel 6 schedule:work

Laravel 6 schedule:work

Dapet dari sini https://github.com/laravel/ideas/issues/2338

<?php


namespace App\Console\Commands;


use Illuminate\Console\Command;

use Illuminate\Support\Facades\Artisan;


class ScheduleListen extends Command

{

    /**

     * The name and signature of the console command.

     *

     * @var string

     */

    protected $signature = 'schedule:listen';


    /**

     * The console command description.

     *

     * @var string

     */

    protected $description = 'Listen for scheduled tasks';


    /**

     * Execute the console command.

     *

     * @return int

     */

    public function handle()

    {

        $this->line('Listening for scheduled tasks..');


        while (true) {

            if(now()->startOfMinute()->is(now())) {

                Artisan::call('schedule:run');

                $output = Artisan::output();

                if($output != 'No scheduled commands are ready to run.') {

                    $this->line($output);

                }

            }


            sleep(1);

        }

    }