1
0
Fork 0

优化设备数据同步命令

develop
李静 2023-05-06 14:18:52 +08:00
parent c551bcafeb
commit 3fcbe33ddc
1 changed files with 18 additions and 13 deletions

View File

@ -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();
}
}