mtjh_watch.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package services
  2. import (
  3. "eta/eta_data_analysis/utils"
  4. "fmt"
  5. "github.com/patrickmn/go-cache"
  6. "io/fs"
  7. "path/filepath"
  8. "time"
  9. )
  10. func mtjhWatch() {
  11. fmt.Println("mtjhWatch start")
  12. var err error
  13. defer func() {
  14. if err != nil {
  15. fmt.Println("mtjhWatch Err:" + err.Error())
  16. }
  17. }()
  18. var cacheClient *cache.Cache
  19. if cacheClient == nil {
  20. cacheClient = cache.New(365*24*time.Hour, 365*24*time.Hour)
  21. }
  22. err = filepath.Walk(utils.MtjhFilePath, func(path string, info fs.FileInfo, err error) error {
  23. if err != nil {
  24. return err
  25. }
  26. if !info.IsDir() {
  27. /*fileInfo, err := os.Stat(path)
  28. if err != nil {
  29. fmt.Println("os.Stat:", err.Error())
  30. }
  31. winFileAttr := fileInfo.Sys().(*syscall.Win32FileAttributeData)
  32. modifyTimeStr := utils.SecondToTime(winFileAttr.LastWriteTime.Nanoseconds() / 1e9).Format(utils.FormatDateTime)
  33. existModifyTime, ok := cacheClient.Get(path)
  34. if ok {
  35. existModifyTimeStr := existModifyTime.(string)
  36. if existModifyTimeStr != modifyTimeStr {
  37. if strings.Contains(path, "煤炭江湖") {
  38. err = Mtjh(path)
  39. }
  40. }
  41. } else {
  42. if strings.Contains(path, "煤炭江湖") {
  43. err = Mtjh(path)
  44. }
  45. }
  46. cacheClient.Delete(path)
  47. cacheClient.Set(path, modifyTimeStr, 24*time.Hour)*/
  48. }
  49. return nil
  50. })
  51. }