onStart method
Callback when this executor is started. Returns true if successfully started, false otherwise.
Implementation
@override
Future<bool> onStart() async {
// sampling might be started after [startTime] or the app wasn't running at [startTime]
// therefore, first check if the random timers have been scheduled for today
if (TimeOfDay.now().isAfter(startTime)) {
if (!hasBeenScheduledForToday) {
debug(
'$runtimeType - timers has not been scheduled for today ($todayString) - scheduling now');
_scheduleTimers();
}
}
// set up a cron job that generates the random triggers once pr day at [startTime]
final cronJob = '${startTime.minute} ${startTime.hour} * * *';
debug('$runtimeType - creating cron job : $cronJob');
_cron.schedule(cron.Schedule.parse(cronJob), () async {
debug('$runtimeType - resuming cron job : ${DateTime.now().toString()}');
_scheduleTimers();
});
return true;
}