ProfileTask.swift 744 B

123456789101112131415161718192021222324252627
  1. // LoopFollow
  2. // ProfileTask.swift
  3. import Foundation
  4. extension MainViewController {
  5. func scheduleProfileTask(initialDelay: TimeInterval = 3) {
  6. let firstRun = Date().addingTimeInterval(initialDelay)
  7. TaskScheduler.shared.scheduleTask(id: .profile, nextRun: firstRun) { [weak self] in
  8. guard let self = self else { return }
  9. self.profileTaskAction()
  10. }
  11. }
  12. func profileTaskAction() {
  13. guard IsNightscoutEnabled() else {
  14. TaskScheduler.shared.rescheduleTask(id: .profile, to: Date().addingTimeInterval(60))
  15. return
  16. }
  17. webLoadNSProfile()
  18. TaskScheduler.shared.rescheduleTask(id: .profile, to: Date().addingTimeInterval(10 * 60))
  19. }
  20. }