logs.go 565 B

12345678910111213141516171819202122232425262728
  1. package services
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "hongze/hz_crm_api/models"
  6. "hongze/hz_crm_api/utils"
  7. )
  8. // the service for log
  9. func AutoInsertLogToDB() {
  10. defer func() {
  11. if err := recover(); err != nil {
  12. fmt.Println("[AutoInsertLogToDB]", err)
  13. }
  14. }()
  15. for {
  16. utils.Rc.Brpop(utils.CACHE_KEY_LOGS, func(b []byte) {
  17. var log models.OperateLogs
  18. if err := json.Unmarshal(b, &log); err != nil {
  19. fmt.Println("json unmarshal wrong!")
  20. }
  21. if _, err := models.AddLogs(&log); err != nil {
  22. fmt.Println("AddLogs:", err.Error(), log)
  23. }
  24. })
  25. }
  26. }