Browse Source

update 存储异常处理

dev
lucas 1 month ago
parent
commit
ebf5081cd2
  1. 14
      storage/storageDBs/storage2Es.go

14
storage/storageDBs/storage2Es.go

@ -47,12 +47,18 @@ func newEsHelper() *dbHelper.ESHelper {
} }
func (the *Storage2Es) SaveRaw(dataList []common_models.EsRaw) { func (the *Storage2Es) SaveRaw(dataList []common_models.EsRaw) {
defer func() {
if err := recover(); err != nil {
log.Printf("未知异常=> %v", err)
}
}()
body := strings.Builder{} body := strings.Builder{}
for _, raw := range dataList { for _, raw := range dataList {
// scala => val id = UUID.nameUUIDFromBytes(s"${v.deviceId}-${v.acqTime.getMillis}".getBytes("UTF-8")).toString // scala => val id = UUID.nameUUIDFromBytes(s"${v.deviceId}-${v.acqTime.getMillis}".getBytes("UTF-8")).toString
source, err := json.Marshal(raw) source, err := json.Marshal(raw)
if err != nil { if err != nil {
log.Printf("序列化异常,err=%s", err.Error()) log.Printf("raw序列化异常,err=%s", err.Error())
continue continue
} }
docId := fmt.Sprintf("%s-%d", raw.IotaDevice, raw.CollectTime.UnixMilli()) docId := fmt.Sprintf("%s-%d", raw.IotaDevice, raw.CollectTime.UnixMilli())
@ -72,7 +78,11 @@ func (the *Storage2Es) SaveTheme(dataList []common_models.EsTheme) {
for _, theme := range dataList { for _, theme := range dataList {
// scala => val id = UUID.nameUUIDFromBytes(s"${sd.station.id}-${sd.acqTime.getMillis}".getBytes("UTF-8")).toString // scala => val id = UUID.nameUUIDFromBytes(s"${sd.station.id}-${sd.acqTime.getMillis}".getBytes("UTF-8")).toString
source, _ := json.Marshal(theme) source, err := json.Marshal(theme)
if err != nil {
log.Printf("theme序列化异常,err=%s", err.Error())
continue
}
_id := common_calc.NameUUIDFromString(fmt.Sprintf("%d-%d", theme.Sensor, theme.CollectTime.UnixMilli())) _id := common_calc.NameUUIDFromString(fmt.Sprintf("%d-%d", theme.Sensor, theme.CollectTime.UnixMilli()))
s := fmt.Sprintf( s := fmt.Sprintf(
`{"index": {"_index": "%s","_id": "%s"}} `{"index": {"_index": "%s","_id": "%s"}}

Loading…
Cancel
Save