在laravel 5中运行cron工作

时间:2015-09-16 11:07:49

标签: php cron laravel-5

我已将我的命令注册为php artisan run:process,它看起来像是

  class queuedTransaction extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'run:process';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Running the queued transaction.';

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

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle(){
       DB::table('transfers')->truncate();
    }

}

这是我的kernel.php

class Kernel extends ConsoleKernel
{

    protected $commands = [
        \App\Console\Commands\Inspire::class,
        \App\Console\Commands\queuedTransaction::class,

    ];


    protected function schedule(Schedule $schedule)
    {


      $schedule->command('run:process')->everyMinute();

    }
}

现在我想每分钟运行php artisan run:process并截断transfers表,但cron现在无效。只是为了确保,如果command本身正在工作,我将command放在我的routes中并调用它,它截断表意味着命令正在执行其工作。

1 个答案:

答案 0 :(得分:0)

在Kernel.php中,您的命令应包含在:

/**                                                                                                             
 * The Artisan commands provided by your application.
 *
 * @var array
 */
 protected $commands = [
     MyCommand::class
 ];

您也可以删除Inspire:)