onResume method

  1. @override
Future<bool> onResume()
override

Resumes sampling based on the samplingState of the deployment.

If the prior samplingState is unknown (null), it simply resumes all executors. If the prior samplingState is known, it resumes or pauses the executors based on the state of each TaskControlExecutor in the samplingState.

Finally, the method enqueues all app tasks buffered in the AppTaskController.

Implementation

@override
Future<bool> onResume() async {
  if (_samplingState == null) {
    await super.onResume();
  } else {
    for (var executor in _executors) {
      if (executor is TaskControlExecutor) {
        var taskControlSamplingState = _samplingState!
            .taskControlSamplingStates
            .firstWhere(
              (state) =>
                  state.triggerId == executor.taskControl.triggerId &&
                  state.taskName == executor.taskControl.taskName,
            );

        if (taskControlSamplingState.state == ExecutorState.Resumed ||
            taskControlSamplingState.state ==
                ExecutorState.PausedButShouldBeResumed) {
          executor.resume();
        } else if (taskControlSamplingState.state == ExecutorState.Paused) {
          executor.pause();
        }
      }
    }
  }

  await AppTaskController().enqueueBufferedTasks();
  debug(
    '$runtimeType resumed - ${await SmartPhoneClientManager().notificationManager.pendingNotificationRequestsCount} notifications are currently pending.',
  );

  return true;
}