Closed emmanuelfrancis closed 3 months ago
Updating schedule with setConfig does not stop the previous schedule
Why not?
@christocracy I am trying to stop the schedule, but if I remove the schedule from the schedule array and call setConfig by passing new array, it still fires onSchedule on previously set time. I also tried calling BackgroundGeolocation.stopSchedule before setting new schedule.
What happens if you await BackgroundGeolocation.stopSchedule()
before .setConfig(newSchedule)
?
Does not work, I wrote exact same, also tried calling .stop
await BackgroundGeolocation.stopSchedule((state) => { }); await BackgroundGeolocation.stop((state) => { }); BackgroundGeolocation.setConfig({ schedule: newSchedule, scheduleUseAlarmManager: true, })
Here I let a schedule event fire and observe the next item get scheduled
06-27 11:37:00.036 31092 31092 I TSLocationManager: ╔═════════════════════════════════════════════
06-27 11:37:00.036 31092 31092 I TSLocationManager: ║ 📅 Schedule alarm fired! enabled: false, trackingMode: 0
06-27 11:37:00.036 31092 31092 I TSLocationManager: ╠═════════════════════════════════════════════
06-27 11:37:00.045 31092 31092 D TSLocationManager: 📅 Day #2: Searching schedule for alarms...
06-27 11:37:00.046 31092 31092 I TSLocationManager: [c.t.l.s.TSScheduleManager a]
06-27 11:37:00.046 31092 31092 I TSLocationManager: 📅 Scheduled Alarm: ON at 11:38 on Monday
06-27 11:37:00.046 31092 31092 D TSLocationManager: [c.t.l.s.TSScheduleManager a]
06-27 11:37:00.046 31092 31092 D TSLocationManager: ℹ️ Schedule with AlarmManager
Then I call .stopSchedule()
:
06-27 11:37:03.026 31092 31092 I TSLocationManager: [c.t.l.s.TSScheduleManager stop]
06-27 11:37:03.026 31092 31092 I TSLocationManager: 🔴 Scheduler OFF
I see no more events fire. The scheduler is stopped. The last scheduled event 📅 Scheduled Alarm: ON at 11:38 on Monday
does not fire.
Google PIxel 6 @ 12.
My logs above prove that calling .stopSchedule()
cancels a currently scheduled event.
You can test the scheduler by scheduling events to occur a minute into the future. You don’t have to wait hours.
Calling .stopSchedule() stops all future/upcoming schedules. Below are my findings:
// Not working
await BackgroundGeolocation.stopSchedule()
BackgroundGeolocation.setConfig({ schedule: newSchedule, scheduleUseAlarmManager: true, }) .then((state1) => {
BackgroundGeolocation.startSchedule().then((state2) => {
});
})
Above code does not stop previous schedule. It keeps previous schedule as well as add new schedule.
I tried below and it works:
// This works
await BackgroundGeolocation.stopSchedule()
await BackgroundGeolocation.setConfig({
schedule: [],
}).then((stateClear) => {
console.log('clean schedule before updates ', stateClear);
});
BackgroundGeolocation.setConfig({ schedule: newSchedule, scheduleUseAlarmManager: true, }) .then((state1) => {
BackgroundGeolocation.startSchedule().then((state2) => {
});
})
Thanks, I’ll test that.
I'm not seeing any issue with changing the schedule on-the-fly. I do not get any incorrect schedule events occur. It does not seem to be required to .stopSchedule()
to update the schedule.
await BackgroundGeolocation.setConfig((
schedule: [
'1-7 13:00-18:00'
]
});
await BackgroundGeolocation.startSchedule();
await BackgroundGeolocation.setConfig({
schedule: [
'1-7 12:55-18:00'
]
});
06-28 12:52:36.757 5841 5841 D TSLocationManager: [c.t.l.adapter.TSConfig d] ℹ️ Persist config, dirty: [schedule]
06-28 12:52:36.760 5841 5841 D TSLocationManager: [c.t.l.s.TSScheduleManager restart]
06-28 12:52:36.760 5841 5841 D TSLocationManager: 📅 Schedule changed: restarting...
06-28 12:52:36.763 5841 5841 I TSLocationManager: [c.t.l.s.TSScheduleManager start]
06-28 12:52:36.763 5841 5841 I TSLocationManager: ╔═════════════════════════════════════════════
06-28 12:52:36.763 5841 5841 I TSLocationManager: ║ 🎾 Scheduler ON
06-28 12:52:36.763 5841 5841 I TSLocationManager: ╠═════════════════════════════════════════════
06-28 12:52:36.763 5841 5841 I TSLocationManager: ╟─ Schedule[13:00-18:00, Days: [1, 2, 3, 4, 5, 6, 7], trackingMode: 1]
06-28 12:52:36.763 5841 5841 I TSLocationManager: ╚═════════════════════════════════════════════
06-28 12:52:36.764 5841 5841 D TSLocationManager: [c.t.l.s.TSScheduleManager a]
06-28 12:52:36.764 5841 5841 D TSLocationManager: 📅 Day #3: Searching schedule for alarms...
06-28 12:52:36.765 5841 5841 I TSLocationManager: [c.t.l.s.TSScheduleManager a]
06-28 12:52:36.765 5841 5841 I TSLocationManager: 📅 Scheduled Alarm: ON at 13:00 on Tuesday
06-28 12:52:36.765 5841 5841 D TSLocationManager: [c.t.l.s.TSScheduleManager a]
06-28 12:52:36.765 5841 5841 D TSLocationManager: ℹ️ Schedule with AlarmManager
06-28 12:52:36.772 5841 5841 W TSLocationManager: [c.t.l.s.TSScheduleManager start] Scheduler already started. IGNORED
06-28 12:52:36.796 5841 5841 D TSLocationManager: [c.t.l.adapter.TSConfig d] ℹ️ Persist config, dirty: [schedule]
06-28 12:52:36.798 5841 5841 D TSLocationManager: [c.t.l.s.TSScheduleManager restart]
06-28 12:52:36.798 5841 5841 D TSLocationManager: 📅 Schedule changed: restarting...
06-28 12:52:36.804 5841 5841 I TSLocationManager: [c.t.l.s.TSScheduleManager start]
06-28 12:52:36.804 5841 5841 I TSLocationManager: ╔═════════════════════════════════════════════
06-28 12:52:36.804 5841 5841 I TSLocationManager: ║ 🎾 Scheduler ON
06-28 12:52:36.804 5841 5841 I TSLocationManager: ╠═════════════════════════════════════════════
06-28 12:52:36.804 5841 5841 I TSLocationManager: ╟─ Schedule[12:55-18:00, Days: [1, 2, 3, 4, 5, 6, 7], trackingMode: 1]
06-28 12:52:36.804 5841 5841 I TSLocationManager: ╚═════════════════════════════════════════════
06-28 12:52:36.805 5841 5841 D TSLocationManager: [c.t.l.s.TSScheduleManager a]
06-28 12:52:36.805 5841 5841 D TSLocationManager: 📅 Day #3: Searching schedule for alarms...
06-28 12:52:36.805 5841 5841 I TSLocationManager: [c.t.l.s.TSScheduleManager a]
06-28 12:52:36.805 5841 5841 I TSLocationManager: 📅 Scheduled Alarm: ON at 12:55 on Tuesday
06-28 12:52:36.806 5841 5841 D TSLocationManager: [c.t.l.s.TSScheduleManager a]
06-28 12:52:36.806 5841 5841 D TSLocationManager: ℹ️ Schedule with AlarmManager
.
.
.
06-28 12:55:00.042 5841 5841 I TSLocationManager: [c.t.l.scheduler.ScheduleEvent onScheduleEvent]
06-28 12:55:00.042 5841 5841 I TSLocationManager: ╔═════════════════════════════════════════════
06-28 12:55:00.042 5841 5841 I TSLocationManager: ║ 📅 Schedule alarm fired! enabled: true, trackingMode: 1
06-28 12:55:00.042 5841 5841 I TSLocationManager: ╠═════════════════════════════════════════════
06-28 12:55:00.069 5841 5841 D TSLocationManager: [c.t.locationmanager.util.c h]
06-28 12:55:00.069 5841 5841 D TSLocationManager: ℹ️ LocationAuthorization: Permission granted
06-28 12:55:00.069 5841 5841 I TSLocationManager: [c.t.l.service.TrackingService changePace]
06-28 12:55:00.069 5841 5841 I TSLocationManager: 🔵 setPace: false → false
06-28 12:55:00.071 5841 5841 D TSLocationManager: [c.t.l.s.TSScheduleManager a]
06-28 12:55:00.071 5841 5841 D TSLocationManager: 📅 Day #3: Searching schedule for alarms...
06-28 12:55:00.072 5841 5841 I TSLocationManager: [c.t.l.s.TSScheduleManager a]
06-28 12:55:00.072 5841 5841 I TSLocationManager: 📅 Scheduled Alarm: OFF at 18:00 on Tuesday
06-28 12:55:00.072 5841 5841 D TSLocationManager: [c.t.l.s.TSScheduleManager a]
06-28 12:55:00.072 5841 5841 D TSLocationManager: ℹ️ Schedule with AlarmManager
I have not seen you post any logs yet? Are you observing your logs?
When .setConfig()
is called with a new schedule
, the plugin correctly detects that and "resets" itself.
06-28 12:52:36.796 5841 5841 D TSLocationManager: [c.t.l.adapter.TSConfig d] ℹ️ Persist config, dirty: [schedule]
06-28 12:52:36.798 5841 5841 D TSLocationManager: [c.t.l.s.TSScheduleManager restart]
06-28 12:52:36.798 5841 5841 D TSLocationManager: 📅 Schedule changed: restarting...
Please check the attached logs.
I tried fetching logs using getLogs but that failed with error "Failed to fetch logs", so its from adb I also do not see any logs which say "Schedule changed" after calling setConfig. TSLocationManager logs appeared only when app was started and when onSchedule and onGeofence fired. When I called setConfig the promise was resolved properly and you can see the logs with "- BackgroundGeolocation setConfig setScheduleUpdate: with state object. geologs.log
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You may also mark this issue as a "discussion" and I will leave this open.
This issue was closed because it has been inactive for 14 days since being marked as stale.
Your Environment
react-native -v
): 0.66.3// On a button "Start Scheduler" click sets the schedule: BackgroundGeolocation.setConfig({ "schedule" : [ "2 20:00-21:00 geofence", "3 20:00-21:30 geofence", ], scheduleUseAlarmManager: true, }) .then((state1) => { BackgroundGeolocation.startSchedule().then((state2) => { }); }) .catch((error) => { });
// On a button "Remove Scheduler" click sets the schedule:
BackgroundGeolocation.setConfig({ "schedule" : [ "3 20:00-21:30 geofence", ], scheduleUseAlarmManager: true, }) .then((state1) => { BackgroundGeolocation.startSchedule().then((state2) => { }); }) .catch((error) => { });