Обновил отправку тегов с массива на построчный формат #8
@@ -28,7 +28,7 @@ function toMetric(payload: DemoPlcPayload, timestamp: number): DemoPlcMetric {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function postMetric(metric: DemoPlcMetric): Promise<void> {
|
async function postMetric(metric: DemoPlcMetric): Promise<void> {
|
||||||
const response = await postCloudIngest([metric])
|
const response = await postCloudIngest(metric)
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const text = await response.text()
|
const text = await response.text()
|
||||||
|
|||||||
@@ -22,14 +22,32 @@ function assertRegisterCount(values: number[]): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function postMetrics(metrics: MappedMetric[]): Promise<void> {
|
async function postMetrics(metrics: MappedMetric[]): Promise<void> {
|
||||||
const response = await postCloudIngest(metrics)
|
const errors: Error[] = []
|
||||||
|
|
||||||
if (!response.ok) {
|
for (const metric of metrics) {
|
||||||
const text = await response.text()
|
try {
|
||||||
throw new Error(text)
|
const response = await postCloudIngest(metric)
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
const text = await response.text()
|
||||||
|
throw new Error(text || `${response.status} ${response.statusText}`)
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
const message = error instanceof Error ? error.message : String(error)
|
||||||
|
errors.push(new Error(`${metric.tag}: ${message}`))
|
||||||
|
console.error('edge5.modbus.v2.metric.failed', metric.tag, message)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('edge5.modbus.v2.posted', { count: metrics.length })
|
console.log('edge5.modbus.v2.posted', {
|
||||||
|
total: metrics.length,
|
||||||
|
succeeded: metrics.length - errors.length,
|
||||||
|
failed: errors.length,
|
||||||
|
})
|
||||||
|
|
||||||
|
if (errors.length) {
|
||||||
|
throw new Error(`Failed to post ${errors.length}/${metrics.length} edge5 modbus v2 metrics`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const handleEdge5ModbusV2: TopicHandler = async (topic, payload) => {
|
export const handleEdge5ModbusV2: TopicHandler = async (topic, payload) => {
|
||||||
|
|||||||
@@ -35,11 +35,13 @@ function toMetrics(values: number[], timestamp: number): Edge5ModbusMetric[] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function postMetrics(metrics: Edge5ModbusMetric[]): Promise<void> {
|
async function postMetrics(metrics: Edge5ModbusMetric[]): Promise<void> {
|
||||||
const response = await postCloudIngest(metrics)
|
for (const metric of metrics) {
|
||||||
|
const response = await postCloudIngest(metric)
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const text = await response.text()
|
const text = await response.text()
|
||||||
throw new Error(text)
|
throw new Error(text)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('edge5.modbus.posted', { count: metrics.length })
|
console.log('edge5.modbus.posted', { count: metrics.length })
|
||||||
|
|||||||
Reference in New Issue
Block a user