tryDeployment method
Verifies whether the primary 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 and the current status
is returned.
Implementation
@override
Future<StudyStatus> tryDeployment({bool useCached = true}) async {
assert(
study != null,
'Cannot deploy without a valid study deployment id and device role name. '
"Call 'addStudy()' or 'addStudyProtocol()' first.");
info('$runtimeType - Trying to deploy study: $study');
if (useCached) {
// restore the deployment and app task queue
bool success = await restoreDeployment();
if (success) {
await AppTaskController().restoreQueue();
return status = deployment?.status ?? StudyStatus.Deployed;
}
}
// if no cache, get the deployment from the deployment service
// and save a local cache
status = await super.tryDeployment();
debug('$runtimeType - Got deployment: $deployment');
if (status == StudyStatus.Deployed && deployment != null) {
deployment!.deployed = DateTime.now().toUtc();
Settings().getCacheBasePath(deployment!.studyDeploymentId);
// if no user is specified for this study, look up the local user id
deployment!.userId ??= await Settings().userId;
deployment?.status = status;
await saveDeployment();
}
return status;
}