Permalink
Browse files

Simplify Upload and add helper methods to wait for validation and upl…

…oad to complete
  • Loading branch information...
1 parent fcb4dcf commit bf0f9ab02ad1b06066cd8bc2c8895029e6f36faa @tism tism committed Oct 16, 2012
Showing with 41 additions and 9 deletions.
  1. +10 −9 IntegrityIntegration/Integrity.cs
  2. +31 −0 IntegrityIntegration/IntegrityInterface.cs
View
19 IntegrityIntegration/Integrity.cs
@@ -139,22 +139,23 @@ public UploadAttemptResponse Upload(IntegrityDataset dataset, DatasetFormat form
UploadAttemptResponse created_status = default(UploadAttemptResponse);
created_status = _integrity_interface.CreateUpload(ref upload_attempt);
-
if (!created_status.WasSuccess)
{
return created_status;
}
- UploadAttemptResponse validated_status = default(UploadAttemptResponse);
- validated_status = _integrity_interface.ValidateUpload(created_status.GetId);
- if (!validated_status.WasSuccess)
+ UploadAttemptResponse validation_status = _integrity_interface.WaitUntilValidated(upload_attempt.ID);
+ if (!validation_status.WasSuccess)
+ {
+ return validation_status;
+ }
+
+ UploadAttemptResponse upload_status = _integrity_interface.Upload(upload_attempt.ID);
+ if (!upload_status.WasSuccess)
{
- return validated_status;
+ return upload_status;
}
- UploadAttemptResponse uploaded_status = default(UploadAttemptResponse);
- uploaded_status = _integrity_interface.Upload(validated_status.GetId);
- return uploaded_status;
-
+ return _integrity_interface.WaitUntilUploaded(upload_attempt.ID);
}
}
View
31 IntegrityIntegration/IntegrityInterface.cs
@@ -62,4 +62,35 @@ public UploadAttemptResponse GetUploadStatus(int upload_attempt_id)
{
return new UploadAttemptResponse(_service.GetUploadStatus(upload_attempt_id));
}
+
+ public UploadAttemptResponse WaitUntilValidated(int upload_attempt_id)
+ {
+ string[] validation_statuses = { "transferring", "pending_validation", "validating" };
+ return WaitUntilNotStatus(upload_attempt_id, validation_statuses);
+ }
+
+ public UploadAttemptResponse WaitUntilUploaded(int upload_attempt_id)
+ {
+ string[] upload_statuses = { "pending_upload", "uploading" };
+ return WaitUntilNotStatus(upload_attempt_id, upload_statuses);
+ }
+
+ private UploadAttemptResponse WaitUntilNotStatus(int upload_attempt_id, string[] statuses)
+ {
+ UploadAttemptResponse response = GetUploadStatus(upload_attempt_id);
+ int attempts = 1;
+
+ while (statuses.Contains(response.status))
+ {
+ if (attempts > 1200)
+ {
+ break;
+ }
+ System.Threading.Thread.Sleep(5000);
+ response = GetUploadStatus(upload_attempt_id);
+ attempts++;
+ }
+
+ return response;
+ }
}

0 comments on commit bf0f9ab

Please sign in to comment.