Laravel多任务sheduler无法正常工作

时间:2019-12-05 07:46:46

标签: laravel task scheduled-tasks

我试图通过使用Laravel任务sheduler执行两个cron作业。我为我的两个任务编写了两个单独的类。第一项任务是发送每日生日祝福的方法,另一项任务是检查费用。这些是我的程序。方法是用控制器文件编写的。这就是我在Kernel中调用这些类的方式:

  protected $commands = [
     \App\Console\Commands\MonthlyFeeCheck::class, \App\Console\Commands\DailyBirthdayCheck::class,

  ];

   protected function schedule(Schedule $schedule) {
      // $schedule->command('inspire')
      //          ->hourly();
      $schedule->command('Fee:repeatCheck')
                    ->everyMinute();
      $schedule->command('Birthday:birthdayCheck')->daily();
    }

我为这两个任务编写了另外两个命令类。 DailyBirthdayCheck.phpMonthlyFeeCheck.php,但是此sheduler无法正常工作。您能帮我解决这个问题吗?

<?php

namespace App\Console\Commands;

use App\Models\StudentDetails;
use App\Models\StudentNotes;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;
use App\Http\Controllers\Student\StudentCommonController;
use App\Http\Controllers\DashboardController;

class DailyBirthdayCheck extends Command {

    protected $signature = 'Birthday:birthdayCheck';
    protected $description = 'check students birthday wishes';
    protected $process;

    public function __construct() {
        parent::__construct();
        $this->student = new StudentCommonController();
        $this->dash = new DashboardController();
    }

    public function handle() {

        $this->dash->sendBirthDayWish();
    }

}

这是代码生日检查。我编写了在仪表板控制器上发送生日祝福的功能。同样,我另外写了一个班月费检查

<?php

namespace App\Console\Commands;

use App\Models\StudentDetails;
use App\Models\StudentNotes;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;
use App\Http\Controllers\Student\StudentCommonController;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\CommonController;

class MonthlyFeeCheck extends Command {

    protected $signature = 'Fee:repeatCheck';

    protected $description = 'check students fee mode and insert new entry in fee repeat table if the current period expires';
    protected $process;

    public function __construct() {
        parent::__construct();
        $this->student = new StudentCommonController();
        $this->common = new CommonController();
        $this->dash = new DashboardController();
    }

    public function handle() {
        $this->student->checkStudentMonthlyFeeCrone();
        $this->common->getDocumentExpiringWeek();
    }

}

1 个答案:

答案 0 :(得分:0)

您是否在服务器上启动了调度程序?

例如通过将以下内容添加到cron中: * * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1

https://laravel.com/docs/6.x/scheduling上的“启动调度程序”部分对此进行了解释

如果您已经了解了,请尝试从使用命令签名调用命令更改为使用其类,即:

protected $commands = [
    \App\Console\Commands\MonthlyFeeCheck::class, 
    \App\Console\Commands\DailyBirthdayCheck::class,
  ];

protected function schedule(Schedule $schedule) {
    $schedule->command(MonthlyFeeCheck::class)->everyMinute();
    $schedule->command(DailyBirthdayCheck::class)->daily();
}