/// <summary> /// Pools the status of the job until completion or timeout /// </summary> /// <param name="JobID"></param> /// <param name="poolingInternvalInMs"></param> /// <param name="numberOfPoolingAttempts"></param> /// <returns>the JobInfoResponse or throws timeout exception</returns> public GetExportJobInfoResponse WaitForExportJobToComplete(string JobID, int poolingInternvalInMs = 1000, int numberOfPoolingAttempts = 60 * 5) { bool ExportAsyncCompleted = false; int getJobInfoAttempts = 0; bool poolingTimeout = false; GetExportJobInfoResponse GetExportJobInfoResponse = null; while (ExportAsyncCompleted == false && poolingTimeout == false) { if (getJobInfoAttempts > 0) { Thread.Sleep(poolingInternvalInMs); } GetExportJobInfoResponse = GetExportJobInfo(JobID); ExportAsyncCompleted = GetExportJobInfoResponse.StatusCode == 1 || GetExportJobInfoResponse.StatusCode == 3; // Succeeded Failed getJobInfoAttempts++; poolingTimeout = (getJobInfoAttempts == numberOfPoolingAttempts); } if (poolingTimeout == true) { throw new PepperiException(string.Format("WaitForExportJobToComplete timed out. poolingInternvalInMs={0}|numberOfPoolingAttempts={1} ms", poolingInternvalInMs, numberOfPoolingAttempts)); } //exportAsyncCompleted return(GetExportJobInfoResponse); }
/// <summary> /// </summary> /// <param name="JobID">JobID returned by ExportAsync</param> /// <returns>Status</returns> public GetExportJobInfoResponse GetExportJobInfo(string JobID) { string RequestUri = string.Format("export/jobinfo/{0}", HttpUtility.UrlEncode(JobID)); Dictionary <string, string> dicQueryStringParameters = new Dictionary <string, string>(); string accept = "application/json"; PepperiHttpClient PepperiHttpClient = new PepperiHttpClient(this.Authentication, this.Logger); PepperiHttpClientResponse PepperiHttpClientResponse = PepperiHttpClient.Get( ApiBaseUri, RequestUri, dicQueryStringParameters, accept); PepperiHttpClient.HandleError(PepperiHttpClientResponse); GetExportJobInfoResponse result = PepperiJsonSerializer.DeserializeOne <GetExportJobInfoResponse>(PepperiHttpClientResponse.Body); //Api returns single object return(result); }