新增调度中心
This commit is contained in:
parent
6db13b9eab
commit
87ec38d1dd
@ -73,7 +73,7 @@ return [
|
|||||||
/**
|
/**
|
||||||
* 常驻 worker 数量
|
* 常驻 worker 数量
|
||||||
*/
|
*/
|
||||||
'static_worker_number' => 1,
|
'static_worker_number' => 4,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 动态可扩展 worker 最大数量
|
* 动态可扩展 worker 最大数量
|
||||||
@ -99,5 +99,7 @@ return [
|
|||||||
*/
|
*/
|
||||||
'error_log' => runtime_path('catch/schedule') . 'schedule-error.log',
|
'error_log' => runtime_path('catch/schedule') . 'schedule-error.log',
|
||||||
],
|
],
|
||||||
|
|
||||||
|
'schedule_kernel' => \catcher\library\ScheduleKernel::class,
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
38
extend/catcher/library/ScheduleKernel.php
Normal file
38
extend/catcher/library/ScheduleKernel.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | CatchAdmin [Just Like ~ ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
namespace catcher\library;
|
||||||
|
|
||||||
|
use catcher\library\crontab\Schedule;
|
||||||
|
|
||||||
|
class ScheduleKernel
|
||||||
|
{
|
||||||
|
protected $schedule;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->schedule = new Schedule();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function run()
|
||||||
|
{
|
||||||
|
$this->schedule->command('catch:cache')->everyThirtySeconds();
|
||||||
|
$this->schedule->command('test')->everyTenSeconds();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function tasks()
|
||||||
|
{
|
||||||
|
$this->run();
|
||||||
|
|
||||||
|
return $this->schedule->getCronTask();
|
||||||
|
}
|
||||||
|
}
|
@ -53,6 +53,11 @@ class Master
|
|||||||
*/
|
*/
|
||||||
protected $master_pid;
|
protected $master_pid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $kernel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* pid 文件名称
|
* pid 文件名称
|
||||||
*
|
*
|
||||||
@ -135,10 +140,8 @@ class Master
|
|||||||
protected function schedule()
|
protected function schedule()
|
||||||
{
|
{
|
||||||
return function () {
|
return function () {
|
||||||
$schedule = new Schedule();
|
$kernel = new $this->kernel;
|
||||||
$schedule->command('catch:cache')->everyThirtySeconds();
|
foreach ($kernel->tasks() as $cron) {
|
||||||
|
|
||||||
foreach ($schedule->getCronTask() as $cron) {
|
|
||||||
if ($cron->can()) {
|
if ($cron->can()) {
|
||||||
list($waiting, $process) = $this->hasWaitingProcess();
|
list($waiting, $process) = $this->hasWaitingProcess();
|
||||||
if ($waiting) {
|
if ($waiting) {
|
||||||
@ -253,6 +256,8 @@ class Master
|
|||||||
file_put_contents($this->getSaveProcessStatusFile(), '');
|
file_put_contents($this->getSaveProcessStatusFile(), '');
|
||||||
|
|
||||||
$this->createTable();
|
$this->createTable();
|
||||||
|
|
||||||
|
$this->kernel = config('catch.schedule.schedule_kernel');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -103,9 +103,7 @@ trait RegisterSignal
|
|||||||
foreach ($this->processes as $pid => $process) {
|
foreach ($this->processes as $pid => $process) {
|
||||||
Process::kill($pid, SIGUSR1);
|
Process::kill($pid, SIGUSR1);
|
||||||
}
|
}
|
||||||
|
|
||||||
usleep(100);
|
usleep(100);
|
||||||
|
|
||||||
$this->saveProcessStatus();
|
$this->saveProcessStatus();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ trait Store
|
|||||||
public function output()
|
public function output()
|
||||||
{
|
{
|
||||||
// 等待信号输出
|
// 等待信号输出
|
||||||
usleep(500);
|
sleep(1);
|
||||||
|
|
||||||
return $this->getProcessStatusInfo();
|
return $this->getProcessStatusInfo();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user