|
|
@@ -29,11 +29,6 @@ class ManDeviceJobHc implements ShouldQueue
|
|
|
$this->url = config('ip.zslf');
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Execute the job.
|
|
|
- *
|
|
|
- * @return void
|
|
|
- */
|
|
|
public function handle()
|
|
|
{
|
|
|
try {
|
|
|
@@ -61,23 +56,77 @@ class ManDeviceJobHc implements ShouldQueue
|
|
|
if (!empty($records)) {
|
|
|
// 批量推入 Redis
|
|
|
\Illuminate\Support\Facades\Redis::rpush($redisKey, ...$records);
|
|
|
+
|
|
|
+ // 【核心修改点】:每次写入数据都重置 Key 的过期时间为 30 分钟 (1800秒)
|
|
|
+ // 只要持续有数据进来,这个 Key 就一直有效
|
|
|
+ // 如果超过 30 分钟没新数据进来(设备关机/下班),Redis 自动删除该 Key
|
|
|
+ \Illuminate\Support\Facades\Redis::expire($redisKey, 1800);
|
|
|
}
|
|
|
|
|
|
// 2. 检查 Redis 里的总条数
|
|
|
$currentCount = \Illuminate\Support\Facades\Redis::llen($redisKey);
|
|
|
|
|
|
// 3. 达到 500 条,执行批量发送
|
|
|
-
|
|
|
if ($currentCount >= $batchSize) {
|
|
|
$this->processBatchSend($redisKey, $batchSize);
|
|
|
}
|
|
|
}
|
|
|
} catch (\Exception $exception) {
|
|
|
- Log::channel('apiLog')->info('hc开始位置', ["param" => $exception->getMessage()]);
|
|
|
+ Log::channel('apiLog')->info('hc开始位置异常', ["param" => $exception->getMessage()]);
|
|
|
+ // 发生异常时可以根据需要选择是否 delete 或 release
|
|
|
$this->delete();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Execute the job.
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+// public function handle()
|
|
|
+// {
|
|
|
+// try {
|
|
|
+// if (empty($this->data['data'])) return;
|
|
|
+//
|
|
|
+// $deviceId = $this->data['data']['deviceId'];
|
|
|
+// $dataPoints = $this->data['data']['dataPoints'] ?? [];
|
|
|
+//
|
|
|
+// if ($this->data['type'] == "dataPoint") {
|
|
|
+// $redisKey = 'buffer:hengchang_data';
|
|
|
+// $batchSize = 500;
|
|
|
+//
|
|
|
+// // 1. 整理数据并推入 Redis 列表
|
|
|
+// $records = [];
|
|
|
+// foreach ($dataPoints as $value) {
|
|
|
+// if (empty($value['value'])) continue;
|
|
|
+//
|
|
|
+// $records[] = json_encode([
|
|
|
+// 'machine_code' => $deviceId . $value['dataPointId'],
|
|
|
+// 'param_value' => floatval($value['value']),
|
|
|
+// 'time' => $this->getNowDay()
|
|
|
+// ]);
|
|
|
+// }
|
|
|
+//
|
|
|
+// if (!empty($records)) {
|
|
|
+// // 批量推入 Redis
|
|
|
+// \Illuminate\Support\Facades\Redis::rpush($redisKey, ...$records);
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 2. 检查 Redis 里的总条数
|
|
|
+// $currentCount = \Illuminate\Support\Facades\Redis::llen($redisKey);
|
|
|
+//
|
|
|
+// // 3. 达到 500 条,执行批量发送
|
|
|
+//
|
|
|
+// if ($currentCount >= $batchSize) {
|
|
|
+// $this->processBatchSend($redisKey, $batchSize);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// } catch (\Exception $exception) {
|
|
|
+// Log::channel('apiLog')->info('hc开始位置', ["param" => $exception->getMessage()]);
|
|
|
+// $this->delete();
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
/**
|
|
|
* 批量处理发送逻辑
|
|
|
*/
|
|
|
@@ -116,7 +165,7 @@ class ManDeviceJobHc implements ShouldQueue
|
|
|
CURLOPT_RETURNTRANSFER => true,
|
|
|
CURLOPT_ENCODING => '',
|
|
|
CURLOPT_MAXREDIRS => 10,
|
|
|
- CURLOPT_TIMEOUT => 0,
|
|
|
+ CURLOPT_TIMEOUT => 15,
|
|
|
CURLOPT_FOLLOWLOCATION => true,
|
|
|
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
|
|
CURLOPT_CUSTOMREQUEST => 'POST',
|