优化设备数据同步命令
parent
c551bcafeb
commit
3fcbe33ddc
|
|
@ -38,29 +38,31 @@ class DeviceLogSyncCommand extends Command
|
||||||
{
|
{
|
||||||
$this->deviceLogService = $deviceLogService;
|
$this->deviceLogService = $deviceLogService;
|
||||||
|
|
||||||
|
$factory = $this->argument('factory');
|
||||||
|
|
||||||
$sleep = (int) value(fn ($sleep) => is_numeric($sleep) ? $sleep : 60, $this->option('sleep'));
|
$sleep = (int) value(fn ($sleep) => is_numeric($sleep) ? $sleep : 60, $this->option('sleep'));
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
$end = now();
|
$this->runSync($factory);
|
||||||
$start = $end->copy()->subHours(1);
|
|
||||||
|
|
||||||
$this->info('------------------------------------------');
|
|
||||||
$this->info('开始时间: '. $start);
|
|
||||||
$this->info('结束时间: '. $end);
|
|
||||||
|
|
||||||
$this->performSync($start, $end);
|
|
||||||
|
|
||||||
$this->info('------------------------------------------');
|
|
||||||
$this->newLine();
|
|
||||||
|
|
||||||
sleep($sleep);
|
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 */
|
/** @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) {
|
foreach ($devices as $device) {
|
||||||
$this->info('==========================================');
|
$this->info('==========================================');
|
||||||
|
|
@ -79,5 +81,8 @@ class DeviceLogSyncCommand extends Command
|
||||||
|
|
||||||
$this->info('==========================================');
|
$this->info('==========================================');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->info('------------------------------------------');
|
||||||
|
$this->newLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue