Cron 运行 不会在服务器上自动安排 运行ning

Cron run schedule not running automatically on the server

我在 Laravel-5.8 应用程序中有这个 cron 作业代码:

App/Console/Commands:

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Models\Hr\HrDesignation;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Auth;
use Exception;
use Notification;
use GuzzleHttp\Client; 
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\GuzzleException;


class UpdateCreateDesignation extends Command
{
    protected $signature = 'updatecreatedesignations';

    protected $description = 'Update or Create Designation';

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

    public function handle()
    {
        $client = new Client();
        $res = $client->request('GET','https://api.cloudjkk.net/jkkapp/profile/all-designations', [
        'query' => ['key' => 'dddddd']
    ])->getBody();

        $clientdatas = json_decode($res->getContents(), true);    
        
        foreach($clientdatas as $clientdata)
        {        
              if ($clientdata['job_title']) {
            $designation = HrDesignation::updateOrCreate([
                'designation_name' => $clientdata['job_title']
            ],
            [
                'description'       => $clientdata['job_description'],
                'company_id'        => 1,          
            ]); 
        }
        }

    } 
}

对于时间表,我在内核中有这段代码,应该 运行 1:00a.m。每天

kernel.php

<?php

namespace App\Console;

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

class Kernel extends ConsoleKernel
{

    protected $commands = [
        'App\Console\Commands\UpdateCreateDesignation',
    ];

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

    protected function commands()
    {

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

我观察到 cron 作业没有按照 01:00 的计划在服务器上 运行ning。

没有错误。

我该如何解决这个问题?

谢谢

您需要确保已在 crontab 中启用调度程序

https://laravel.com/docs/7.x/scheduling#introduction

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

Laravel 需要每分钟 运行 php artisan schedule:run。如果当前时间是 01:00,则执行该任务。

所以你需要:

  • 每分钟添加一个 cronjob * * * * *
  • 进入目录cd /path-to-your-project
  • 运行 将匹配时间的 artisan 命令 php artisan schedule:run

如果您使用 ->everyMinute();

添加工作,您可以对此进行测试
$schedule->command('increment-db-int')
    ->everyMinute();