sync_pwd_log.go 727 B

1234567891011121314151617181920212223242526272829303132
  1. package service
  2. import (
  3. "context"
  4. "time"
  5. "go-common/library/log"
  6. )
  7. func (s *Service) syncPwdLog() {
  8. id := s.c.Sync.SyncPwdID
  9. for {
  10. pwds, err := s.d.BatchGetPwdLog(context.Background(), id)
  11. if err != nil {
  12. log.Error("failed to batch get pwd log, s.d.BatchGetPwdLog(%d), error(%v)", id, err)
  13. time.Sleep(1 * time.Second)
  14. continue
  15. }
  16. log.Info("SyncPwdID (%d), len(pwds) (%d)", id, len(pwds))
  17. if len(pwds) == 0 {
  18. break
  19. }
  20. for _, pwd := range pwds {
  21. if err := s.d.AddPwdLogHBase(context.Background(), pwd); err != nil {
  22. log.Error("failed to add pwd log to hbase, service.dao.AddLoginLogHBase(%+v) error(%v)", pwd, err)
  23. time.Sleep(1 * time.Second)
  24. continue
  25. }
  26. id = pwd.ID
  27. }
  28. }
  29. }