enqueue method
Future<UserTask?>
enqueue(
- AppTaskExecutor<
AppTask> executor, { - DateTime? triggerTime,
- bool sendNotification = true,
Creates a UserTask for the AppTask run by executor and enqueues it.
triggerTime is when the task becomes available; defaults to now.
If sendNotification and notificationsEnabled are true, the
NotificationManager is asked to show a notification now (if
triggerTime is null) or to schedule one for triggerTime. It still
skips tasks with AppTask.notification off and past trigger times.
Returns null if no UserTaskFactory is registered for the task's type.
Implementation
Future<UserTask?> enqueue(AppTaskExecutor executor, {DateTime? triggerTime, bool sendNotification = true}) async {
if (_userTaskFactories[executor.task.type] == null) {
warning(
'$runtimeType - Could not enqueue AppTask. Could not find a factory for creating '
"a UserTask for type '${executor.task.type}'",
);
return null;
} else {
UserTask userTask = _userTaskFactories[executor.task.type]!.create(executor);
userTask.state = UserTaskState.enqueued;
userTask.enqueued = DateTime.now();
userTask.triggerTime = triggerTime ?? DateTime.now();
_userTaskMap[userTask.id] = userTask;
_controller.add(userTask);
debug('$runtimeType - Enqueued $userTask');
if (notificationsEnabled && sendNotification) {
// create notification
(triggerTime == null)
? await notificationManager.createTaskNotification(userTask)
: await notificationManager.scheduleTaskNotification(userTask);
}
return userTask;
}
}