elec_syncdb.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package service
  2. import (
  3. "context"
  4. "runtime/debug"
  5. "time"
  6. "go-common/app/job/main/ugcpay/model"
  7. "go-common/library/log"
  8. )
  9. // SyncElecOrderList 同步老充电订单
  10. func (s *Service) SyncElecOrderList(c context.Context) {
  11. defer func() {
  12. if x := recover(); x != nil {
  13. log.Error("syncElecOrderSync panic(%+v) :\n %s", x, debug.Stack())
  14. }
  15. }()
  16. var (
  17. limit = 100
  18. list = make([]*model.DBOldElecPayOrder, limit)
  19. startID = int64(0)
  20. err error
  21. )
  22. log.Info("Start syncElecOrderSync from elec_pay_order")
  23. for len(list) >= limit {
  24. log.Info("sync progress elec_pay_order fromID (%d)", startID)
  25. // 1. load old data
  26. if startID, list, err = s.dao.OldElecOrderList(_ctx, startID, limit); err != nil {
  27. log.Error("%+v", err)
  28. return
  29. }
  30. // 2. save new data
  31. for _, ele := range list {
  32. if err = s.handleElecOrder(_ctx, ele); err != nil {
  33. log.Error("s.handleElecOrder: %+v, err: %+v", ele, err)
  34. return
  35. }
  36. }
  37. // 3. give db a break time
  38. time.Sleep(time.Millisecond * 20)
  39. }
  40. log.Info("End syncElecOrderSync from elec_pay_order")
  41. }
  42. // SyncElecMessageList 同步老充电留言
  43. func (s *Service) SyncElecMessageList(c context.Context) {
  44. defer func() {
  45. if x := recover(); x != nil {
  46. log.Error("syncElecMessageList panic(%+v) :\n %s", x, debug.Stack())
  47. }
  48. }()
  49. var (
  50. limit = 100
  51. list = make([]*model.DBOldElecMessage, limit)
  52. startID = int64(0)
  53. err error
  54. )
  55. log.Info("Start syncElecMessageList from elec_message")
  56. for len(list) >= limit {
  57. log.Info("sync progress elec_message fromID (%d)", startID)
  58. // 1. load old data
  59. if startID, list, err = s.dao.OldElecMessageList(_ctx, startID, limit); err != nil {
  60. log.Error("%+v", err)
  61. return
  62. }
  63. // 2. save new data
  64. for _, ele := range list {
  65. if err = s.handleOldElecMessage(_ctx, ele); err != nil {
  66. log.Error("s.handleOldElecMessage: %+v, err: %+v", ele, err)
  67. return
  68. }
  69. }
  70. // 3. give db a break time
  71. time.Sleep(time.Millisecond * 20)
  72. }
  73. log.Info("End syncElecMessageList from elec_message")
  74. }