From 3fcbe33ddc0a5e60c454f77cd98d070dffe50cc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Sat, 6 May 2023 14:18:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=AE=BE=E5=A4=87=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=90=8C=E6=AD=A5=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/Commands/DeviceLogSyncCommand.php | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/app/Console/Commands/DeviceLogSyncCommand.php b/app/Console/Commands/DeviceLogSyncCommand.php index e727132..d5ea029 100644 --- a/app/Console/Commands/DeviceLogSyncCommand.php +++ b/app/Console/Commands/DeviceLogSyncCommand.php @@ -38,29 +38,31 @@ class DeviceLogSyncCommand extends Command { $this->deviceLogService = $deviceLogService; + $factory = $this->argument('factory'); + $sleep = (int) value(fn ($sleep) => is_numeric($sleep) ? $sleep : 60, $this->option('sleep')); while (true) { - $end = now(); - $start = $end->copy()->subHours(1); - - $this->info('------------------------------------------'); - $this->info('开始时间: '. $start); - $this->info('结束时间: '. $end); - - $this->performSync($start, $end); - - $this->info('------------------------------------------'); - $this->newLine(); + $this->runSync($factory); sleep($sleep); }; } - protected function performSync(Carbon $start, Carbon $end): void + /** + * 执行同步 + */ + protected function runSync(string $factory): void { + $end = now(); + $start = $end->copy()->subHours(1); + + $this->info('------------------------------------------'); + $this->info('开始时间: '. $start); + $this->info('结束时间: '. $end); + /** @var \Illuminate\Database\Eloquent\Collection */ - $devices = Device::with(['factory'])->poweredBy($this->argument('factory'))->get(); + $devices = Device::with(['factory'])->poweredBy($factory)->get(); foreach ($devices as $device) { $this->info('=========================================='); @@ -79,5 +81,8 @@ class DeviceLogSyncCommand extends Command $this->info('=========================================='); } + + $this->info('------------------------------------------'); + $this->newLine(); } }