task.go 855 B

1234567891011121314151617181920212223242526272829
  1. package timer
  2. import (
  3. "github.com/robfig/cron"
  4. "smart_tunnel_edge/service"
  5. "smart_tunnel_edge/util/config"
  6. "time"
  7. )
  8. var commandQueue = make(chan []byte, 5)
  9. func TimeTasks() {
  10. c := cron.New()
  11. _ = c.AddFunc("0 */5 * * * ?", func() { //0/5 * * * * ?
  12. if config.Instance().Policy.Id == 3 { //如果当前策略是定时改变光照亮度
  13. endTime := config.Instance().Policy.EndTime
  14. startTime := config.Instance().Policy.StartTime
  15. currentTime := time.Now().Format("15:04")
  16. if currentTime == startTime {
  17. //开灯,将两条路亮度调高
  18. service.OperationLampSwitchJudge([]int8{1, 2}, service.MediumLightLevel, service.MediumPower)
  19. } else if currentTime == endTime {
  20. //关灯,将两条路亮度调低
  21. service.OperationLampSwitchJudge([]int8{1, 2}, service.LowLightLevel, service.LowPower)
  22. }
  23. }
  24. })
  25. c.Start()
  26. }