onInitialize method

  1. @override
bool onInitialize()
override

Callback when this executor is initialized. Returns true if succesfully initialized, false othervise.

Note that this is a non-async method and should hence be 'light-weight' and not block execution for a long duration.

Implementation

@override
bool onInitialize() {
  if (configuration == null) {
    warning(
        'Trying to initialize StudyDeploymentExecutor but the deployment configuration is null. Cannot initialize study deployment.');
    return false;
  }

  group.add(_manualDataPointController.stream);

  for (var triggeredTask in configuration!.triggeredTasks) {
    // get the trigger based on the trigger id
    Trigger trigger = configuration!.triggers['${triggeredTask.triggerId}']!;
    // get the task based on the task name
    TaskDescriptor task =
        configuration!.getTaskByName(triggeredTask.taskName)!;

    TriggeredTaskExecutor executor = getTriggeredTaskExecutor(
      triggeredTask,
      trigger,
      task,
    );

    executor.initialize(triggeredTask, deployment!);

    // let the device manger know about this executor
    if (triggeredTask.targetDeviceRoleName != null) {
      DeviceDescriptor? targetDevice = configuration
          ?.getDeviceFromRoleName(triggeredTask.targetDeviceRoleName!);
      if (targetDevice != null) {
        DeviceController()
            .getDevice(targetDevice.type)
            ?.executors
            .add(executor);
      }
    }

    group.add(executor.data);
    executors.add(executor);
  }
  return true;
}