parallel.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package dao
  2. import (
  3. "go-common/app/service/bbq/recsys/dao/parallel"
  4. "github.com/Dai0522/workpool"
  5. )
  6. // parallelTask2 .
  7. func (d *Dao) parallelTask2(tasks map[string]workpool.Task) map[string]workpool.FutureTask {
  8. ftMap := make(map[string]workpool.FutureTask)
  9. for name, task := range tasks {
  10. ft := workpool.NewFutureTask(task)
  11. retry := 0
  12. err := d.wp.Submit(ft)
  13. for err != nil && retry < 3 {
  14. err = d.wp.Submit(ft)
  15. retry++
  16. }
  17. ftMap[name] = *ft
  18. }
  19. return ftMap
  20. }
  21. // parallelTask .
  22. func (d *Dao) parallelTask(tasks []workpool.Task) *[]workpool.FutureTask {
  23. ftArr := make([]workpool.FutureTask, len(tasks))
  24. for i := range tasks {
  25. ft := workpool.NewFutureTask(tasks[i])
  26. retry := 0
  27. err := d.wp.Submit(ft)
  28. for err != nil && retry < 3 {
  29. err = d.wp.Submit(ft)
  30. retry++
  31. }
  32. ftArr[i] = *ft
  33. }
  34. return &ftArr
  35. }
  36. // ParallelRedis run redis cmd parallel
  37. func (d *Dao) ParallelRedis(tasks *[]parallel.RedisTask) *[]workpool.FutureTask {
  38. ftArr := make([]workpool.FutureTask, len(*tasks))
  39. for i := range *tasks {
  40. ft := workpool.NewFutureTask(&(*tasks)[i])
  41. retry := 0
  42. err := d.wp.Submit(ft)
  43. for err != nil && retry < 3 {
  44. err = d.wp.Submit(ft)
  45. retry++
  46. }
  47. ftArr[i] = *ft
  48. }
  49. return &ftArr
  50. }