gpt4 book ai didi

Laravel - Cron 作业不会在实时服务器上自动更新

转载 作者:行者123 更新时间:2023-12-04 04:05:01 25 4
gpt4 key购买 nike

我的 Digital Ocean Ubuntu 实时服务器上有这个 cron 作业:

namespace App\Console\Commands;
App/Console/Command

class UpdateCreateEmployeeDepartment extends Command
{

protected $signature = 'updatecreateemployeedepartments';

protected $description = 'Update or Create Employee Department';

public function __construct()
{
parent::__construct();
}

public function handle()
{
// Select all employees that haven't been updated
$employees = HrEmployee::where('is_nav_updated', 0)->where('company_id', 1)->get();


// For each of the employees selected above
foreach ($employees as $employee) {
$department = HrDepartment::where('dept_code', $employee->nav_dept_id)->where('company_id', 1)->first();

// If a department was found, update the employee
if ($department) {
$employee->department_id = $department->id;
$employee->is_nav_updated = 1;
$employee->save();
}

}

}

}

cron 作业未按计划在 Live 服务器上自动运行。请参阅下面的控制台

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{

protected $commands = [

'App\Console\Commands\UpdateCreateEmployeeDepartment',
];

protected function schedule(Schedule $schedule)
{
$schedule->command('updatecreateemployeedepartments')
->dailyAt('01:00');
}

protected function commands()
{
$this->load(__DIR__.'/Commands');

require base_path('routes/console.php');
}
}

我观察到它没有按计划自动运行,直到我手动运行:

php artisan updatecreateemployeedepartments

我该如何解决?

谢谢

最佳答案

您想在服务器中运行以下命令以自动运行。

* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1

更多信息查看Starting The Scheduler

关于Laravel - Cron 作业不会在实时服务器上自动更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62667775/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com