Laravel多任务调度程序不工作
我试图使用Laravel任务调度程序执行两个cron作业。我已经为我的两个任务写了两个独立的类。第一个任务是发送每日生日祝福的方法,另一个任务是检查费用。这些是我的节目。方法写在控制器文件中。这就是我在Laravel多任务调度程序不工作,laravel,task,scheduled-tasks,Laravel,Task,Scheduled Tasks,我试图使用Laravel任务调度程序执行两个cron作业。我已经为我的两个任务写了两个独立的类。第一个任务是发送每日生日祝福的方法,另一个任务是检查费用。这些是我的节目。方法写在控制器文件中。这就是我在内核中调用这些类的方式: protected $commands = [ \App\Console\Commands\MonthlyFeeCheck::class, \App\Console\Commands\DailyBirthdayCheck::class, ];
内核中调用这些类的方式:
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.php
和MonthlyFeeCheck.php
,但此调度程序不工作。你能帮我解决这个问题吗
<?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();
}
}
您是否启动了服务器上的计划程序
例如,通过向cron添加以下内容:
***cd/项目路径和php artisan计划:运行>>/dev/null 2>&1
这将在上的“启动调度程序”一节中解释
如果已经介绍了这一点,请尝试从使用命令签名调用命令改为使用其类,即:
受保护的$commands=[
\App\Console\Commands\MonthlyFeeCheck::class,
\App\Console\Commands\DailyBirthdayCheck::class,
];
受保护功能计划(计划$schedule){
$schedule->command(MonthlyFeeCheck::class)->everyMinute();
$schedule->command(DailyBirthdayCheck::class)->daily();
}
什么“不起作用”?你预期会发生什么?实际发生了什么?你为什么要调用一个控制器,它们与请求和响应有关为什么不在类每日生日检查中定义这个变量$this->student,$this->common,$this->dash
,MonthlyFeeCheck
像公共$student
?实际上,feecheck很早就开始工作了。现在我添加了生日选项。。我会试试你的建议。
<?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();
}
}