Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

glow run block when read big file data to mysql #91

Open
huanmengerkong opened this issue Jun 2, 2022 · 2 comments
Open

glow run block when read big file data to mysql #91

huanmengerkong opened this issue Jun 2, 2022 · 2 comments

Comments

@huanmengerkong
Copy link

flow.New().Source(func(chVipDataGlow chan [][]string) {
	defer close(chVipDataGlow)
	file, err := os.Open(fileName)
	fileInfo, err := os.Stat(fileName)
	if err != nil || fileInfo.Size() == 0 {
		return
	}
	defer func() {
		file.Close()
		os.Remove(fileName)
	}()
	if err != nil {
		log.Info(cc).Msgf("企业%d, 打开SFTP文件失败: %v 路径是:%s", enterpriseId, err, fileName)
		return
	}
	buf := bufio.NewReader(file)
	num := 2000
	// var tmp = make([][]string, 0, num
	var tmp [][]string
	var i = 0
	for {
		b, err := buf.ReadString('\n')
		if err != nil && err != io.EOF {
			log.Info(cc).Msgf("数据读取报错了%+v\n", err)
			break
		}
		i++
		cell := strings.Split(b, ",")
		if i == 1 && cell[0] == "数据更新时间" {
			continue
		}
		if len(cell) <= 1 {
			fileCountNumbers += 1
			continue
		}
		tmp = append(tmp, cell)
		if len(tmp) == num {
			fileCountNumbers += num
			chVipDataGlow <- tmp
			tmp = [][]string{}
		}
		if err != nil || err == io.EOF {
			log.Info(cc).Msgf("数据读完了或者报错了%+v", err)
			break
		}
	}
	if len(tmp) > 0 {
		fileCountNumbers += len(tmp)
		chVipDataGlow <- tmp
		tmp = [][]string{}
	}
}, 10).Map(func(params [][]string) [][]string {
	defer func() {
		if errs := recover(); errs != nil {
			log.Error(cc).Msgf("数据库插入执行异常了%+v", errs)
			errDefer = append(errDefer, params...)
			return
		}
	}()
	if len(params) > 0 {
		sucn, ern, _, errData := c.readDataToTableOneByOne(cc, params, enterpriseId)
		errNums += ern
		successNums += sucn
		return errData
	}
	return params
}).Map(func(errItems [][]string) {
        fmt.println(errItems)
}).Run()

11
2
3

@huanmengerkong
Copy link
Author

urgent,urgent,urgent,urgent,urgent .please help !!!

@huanmengerkong
Copy link
Author

This file 200MB

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant