tryDeployment method

  1. @mustCallSuper
Future<StudyStatus> tryDeployment(
  1. String studyDeploymentId,
  2. String deviceRoleName
)
inherited

Verifies whether the device is ready for deployment of the study runtime identified by studyDeploymentId and deviceRoleName, and in case it is, deploys. Also runs for a study that is already deployed, to refresh its deployment information. Returns the study's status afterwards.

Throws NotConfiguredException if the client has not yet been configured. Throws IllegalArgumentException if a study with the given studyDeploymentId and deviceRoleName has not been added. Most other deployment failures do not throw; they are reported on the study as StudyStatusEventTypes.DeploymentError events.

Returns the new StudyStatus of the study.

Implementation

@mustCallSuper
Future<StudyStatus> tryDeployment(String studyDeploymentId, String deviceRoleName) async {
  _checkConfiguration();

  var study = getStudy(studyDeploymentId, deviceRoleName);

  if (study == null) {
    throw IllegalArgumentException(
      "A study with the study deployment ID '$studyDeploymentId' "
      "and device role name '$deviceRoleName' was not found. "
      "Has this study been added using the addStudy method?",
    );
  }
  var status = study.status;

  // Early out in case this study has already received and validated
  // deployment information and is running.
  // if (study.status == StudyStatus.Running) return study.status;
  // TODO: Should not check for this? Allow for re-deployment?
  // if (study.isDeployed) return study.status;

  // Try to deploy the study.
  await proxy?.tryDeployment(study, registration);

  var newStatus = study.status;
  if (status != newStatus) repository.updateStudy(study);
  return newStatus;
}