tryDeployment method

  1. @override
Future<StudyStatus> tryDeployment({
  1. bool useCached = true,
})
override

Verifies whether the master device is ready for deployment and in case it is, deploy the study previously added.

If useCached is true (default), a previously cached deployment will be retrieved from the phone locally. If useCached is false, the deployment will be retrieved from the deploymentService, based on the study.

In case already deployed, nothing happens.

Implementation

@override
Future<StudyStatus> tryDeployment({bool useCached = true}) async {
  assert(
      study != null && device != null,
      'Cannot deploy without a valid study deployment id and device role name. '
      "Call 'initialize()' first.");

  // check cache
  if (useCached) {
    // restore the deployment and app task queue
    bool success = await restoreDeployment();
    await AppTaskController().restoreQueue();
    if (success) {
      status = StudyStatus.Deployed;
      return status;
    }
  }

  // if no cache, get the deployment from the deployment service
  // and save a local cache
  status = await super.tryDeployment();
  if (status == StudyStatus.Deployed) deployment!.deployed = DateTime.now();
  await saveDeployment();
  return status;
}