From 87ec38d1dd4fe25c910200227d2267aeafeaaf2a Mon Sep 17 00:00:00 2001 From: JaguarJack Date: Fri, 10 Jul 2020 08:35:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=B0=83=E5=BA=A6=E4=B8=AD?= =?UTF-8?q?=E5=BF=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/catch.php | 4 +- extend/catcher/library/ScheduleKernel.php | 38 +++++++++++++++++++ extend/catcher/library/crontab/Master.php | 13 +++++-- .../library/crontab/RegisterSignal.php | 2 - extend/catcher/library/crontab/Store.php | 2 +- 5 files changed, 51 insertions(+), 8 deletions(-) create mode 100644 extend/catcher/library/ScheduleKernel.php diff --git a/config/catch.php b/config/catch.php index 59791dd..8714b2a 100644 --- a/config/catch.php +++ b/config/catch.php @@ -73,7 +73,7 @@ return [ /** * 常驻 worker 数量 */ - 'static_worker_number' => 1, + 'static_worker_number' => 4, /** * 动态可扩展 worker 最大数量 @@ -99,5 +99,7 @@ return [ */ 'error_log' => runtime_path('catch/schedule') . 'schedule-error.log', ], + + 'schedule_kernel' => \catcher\library\ScheduleKernel::class, ], ]; diff --git a/extend/catcher/library/ScheduleKernel.php b/extend/catcher/library/ScheduleKernel.php new file mode 100644 index 0000000..408bd07 --- /dev/null +++ b/extend/catcher/library/ScheduleKernel.php @@ -0,0 +1,38 @@ +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(); + } +} \ No newline at end of file diff --git a/extend/catcher/library/crontab/Master.php b/extend/catcher/library/crontab/Master.php index f44a076..c25f747 100644 --- a/extend/catcher/library/crontab/Master.php +++ b/extend/catcher/library/crontab/Master.php @@ -53,6 +53,11 @@ class Master */ protected $master_pid; + /** + * @var string + */ + protected $kernel; + /** * pid 文件名称 * @@ -135,10 +140,8 @@ class Master protected function schedule() { return function () { - $schedule = new Schedule(); - $schedule->command('catch:cache')->everyThirtySeconds(); - - foreach ($schedule->getCronTask() as $cron) { + $kernel = new $this->kernel; + foreach ($kernel->tasks() as $cron) { if ($cron->can()) { list($waiting, $process) = $this->hasWaitingProcess(); if ($waiting) { @@ -253,6 +256,8 @@ class Master file_put_contents($this->getSaveProcessStatusFile(), ''); $this->createTable(); + + $this->kernel = config('catch.schedule.schedule_kernel'); } /** diff --git a/extend/catcher/library/crontab/RegisterSignal.php b/extend/catcher/library/crontab/RegisterSignal.php index 95db3e8..19b0b76 100644 --- a/extend/catcher/library/crontab/RegisterSignal.php +++ b/extend/catcher/library/crontab/RegisterSignal.php @@ -103,9 +103,7 @@ trait RegisterSignal foreach ($this->processes as $pid => $process) { Process::kill($pid, SIGUSR1); } - usleep(100); - $this->saveProcessStatus(); }; } diff --git a/extend/catcher/library/crontab/Store.php b/extend/catcher/library/crontab/Store.php index b34342c..e51b4c4 100644 --- a/extend/catcher/library/crontab/Store.php +++ b/extend/catcher/library/crontab/Store.php @@ -48,7 +48,7 @@ trait Store public function output() { // 等待信号输出 - usleep(500); + sleep(1); return $this->getProcessStatusInfo(); }