优化命令

dev
Jing Li 2024-01-10 15:07:23 +08:00
parent 9407d89f23
commit 5bd37b9ce4
6 changed files with 54 additions and 25 deletions

View File

@ -12,6 +12,7 @@ use App\Models\SoilMonitoringDailyLog;
use App\Models\SoilMonitoringLog;
use App\Services\BiAngDeviceService;
use Illuminate\Console\Command;
use Throwable;
class DeviceLogDailyReportCommand extends Command
{
@ -43,11 +44,15 @@ class DeviceLogDailyReportCommand extends Command
$sleep = (int) value(fn ($sleep) => is_numeric($sleep) ? $sleep : 300, $this->option('sleep'));
while (true) {
/** @var \Illuminate\Database\Eloquent\Collection */
$devices = Device::supplierBy("device-supplier-biang")->get();
try {
/** @var \Illuminate\Database\Eloquent\Collection */
$devices = Device::supplierBy("device-supplier-biang")->get();
foreach ($devices as $device) {
$this->createReport($device);
foreach ($devices as $device) {
$this->createReport($device);
}
} catch (Throwable $e) {
report($e);
}
sleep($sleep);

View File

@ -10,6 +10,7 @@ use App\Models\MeteorologicalMonitoringLog;
use App\Models\SoilMonitoringLog;
use App\Services\BiAngDeviceService;
use Illuminate\Console\Command;
use Throwable;
class DeviceLogReportCommand extends Command
{
@ -41,11 +42,15 @@ class DeviceLogReportCommand extends Command
$sleep = (int) value(fn ($sleep) => is_numeric($sleep) ? $sleep : 300, $this->option('sleep'));
while (true) {
/** @var \Illuminate\Database\Eloquent\Collection */
$devices = Device::supplierBy("device-supplier-biang")->get();
try {
/** @var \Illuminate\Database\Eloquent\Collection */
$devices = Device::supplierBy("device-supplier-biang")->get();
foreach ($devices as $device) {
$this->createReport($device);
foreach ($devices as $device) {
$this->createReport($device);
}
} catch (Throwable $e) {
report($e);
}
sleep($sleep);

View File

@ -39,7 +39,11 @@ class DeviceLogSyncCommand extends Command
$sleep = (int) value(fn ($sleep) => is_numeric($sleep) ? $sleep : 60, $this->option('sleep'));
while (true) {
$this->sync();
try {
$this->sync();
} catch (Throwable $e) {
report($e);
}
sleep($sleep);
};

View File

@ -8,6 +8,7 @@ use App\Models\InsecticidalLampDailyReport;
use App\Models\InsecticidalLampReport;
use App\Services\YunFeiDeviceService;
use Illuminate\Console\Command;
use Throwable;
class DeviceLogDailyReportCommand extends Command
{
@ -39,11 +40,15 @@ class DeviceLogDailyReportCommand extends Command
$seconds = (int) value(fn ($seconds) => is_numeric($seconds) ? $seconds : 300, $this->option('sleep'));
while (true) {
/** @var \Illuminate\Database\Eloquent\Collection */
$devices = Device::supplierBy('device-supplier-yunfei')->get();
try {
/** @var \Illuminate\Database\Eloquent\Collection */
$devices = Device::supplierBy('device-supplier-yunfei')->get();
foreach ($devices as $device) {
$this->createReport($device);
foreach ($devices as $device) {
$this->createReport($device);
}
} catch (Throwable $e) {
report($e);
}
sleep($seconds);

View File

@ -8,6 +8,7 @@ use App\Models\DeviceLog;
use App\Models\InsecticidalLampReport;
use App\Services\YunFeiDeviceService;
use Illuminate\Console\Command;
use Throwable;
class DeviceLogReportCommand extends Command
{
@ -39,11 +40,15 @@ class DeviceLogReportCommand extends Command
$seconds = (int) value(fn ($seconds) => is_numeric($seconds) ? $seconds : 300, $this->option('sleep'));
while (true) {
/** @var \Illuminate\Database\Eloquent\Collection */
$devices = Device::supplierBy('device-supplier-yunfei')->get();
try {
/** @var \Illuminate\Database\Eloquent\Collection */
$devices = Device::supplierBy('device-supplier-yunfei')->get();
foreach ($devices as $device) {
$this->createReport($device);
foreach ($devices as $device) {
$this->createReport($device);
}
} catch (Throwable $e) {
report($e);
}
sleep($seconds);

View File

@ -11,6 +11,7 @@ use Illuminate\Console\Command;
use Illuminate\Support\Arr;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Storage;
use Throwable;
class WormReportCommand extends Command
{
@ -37,15 +38,19 @@ class WormReportCommand extends Command
$seconds = (int) value(fn ($seconds) => is_numeric($seconds) ? $seconds : 60, $this->option('sleep'));
while (true) {
/** @var \Illuminate\Database\Eloquent\Collection */
$devices = Device::with(['project'])
->supplierBy('device-supplier-yunfei')
->where('type', DeviceType::Worm)
->get();
try {
/** @var \Illuminate\Database\Eloquent\Collection */
$devices = Device::with(['project'])
->supplierBy('device-supplier-yunfei')
->where('type', DeviceType::Worm)
->get();
foreach ($devices as $device) {
$this->info('==================================');
$this->createReport($device);
foreach ($devices as $device) {
$this->info('==================================');
$this->createReport($device);
}
} catch (Throwable $e) {
report($e);
}
sleep($seconds);