From b9e5150d807f4d2e29320ce95d53861c2042f7e4 Mon Sep 17 00:00:00 2001 From: Tomek Melissa Date: Mon, 9 Apr 2018 23:30:57 +0200 Subject: [PATCH] Retry request for package URL. --- Common/Helpers/HttpClientHelper.cs | 55 ++++++--------------- Job.Export/Export.cs | 12 ++++- Job.Export/Properties/Resources.Designer.cs | 9 ++++ Job.Export/Properties/Resources.resx | 3 ++ Scheduler/App.config | 2 +- Scheduler/Forms/ExportJob.Designer.cs | 2 +- 6 files changed, 40 insertions(+), 43 deletions(-) diff --git a/Common/Helpers/HttpClientHelper.cs b/Common/Helpers/HttpClientHelper.cs index 6f2512d..c04e517 100644 --- a/Common/Helpers/HttpClientHelper.cs +++ b/Common/Helpers/HttpClientHelper.cs @@ -236,10 +236,6 @@ namespace RecurringIntegrationsScheduler.Common.Helpers /// temp writable cloud url public async Task GetAzureWriteUrl() { - //var requestUri = new UriBuilder(_settings.AosUri) - //{ - // Path = "data/DataManagementDefinitionGroups/Microsoft.Dynamics.DataEntities.GetAzureWriteUrl" - //}; var requestUri = GetAosRequestUri("data/DataManagementDefinitionGroups/Microsoft.Dynamics.DataEntities.GetAzureWriteUrl"); string uniqueFileName = Guid.NewGuid().ToString(); @@ -266,10 +262,6 @@ namespace RecurringIntegrationsScheduler.Common.Helpers /// job's execution status public async Task GetExecutionSummaryStatus(string executionId) { - //var requestUri = new UriBuilder(_settings.AosUri) - //{ - // Path = "data/DataManagementDefinitionGroups/Microsoft.Dynamics.DataEntities.GetExecutionSummaryStatus" - //}; var requestUri = GetAosRequestUri("data/DataManagementDefinitionGroups/Microsoft.Dynamics.DataEntities.GetExecutionSummaryStatus"); var parameters = new { executionId }; @@ -289,20 +281,23 @@ namespace RecurringIntegrationsScheduler.Common.Helpers /// exorted package Url location public async Task GetExportedPackageUrl(string executionId) { - //var requestUri = new UriBuilder(_settings.AosUri) - //{ - // Path = "data/DataManagementDefinitionGroups/Microsoft.Dynamics.DataEntities.GetExportedPackageUrl" - //}; - var requestUri = GetAosRequestUri("data/DataManagementDefinitionGroups/Microsoft.Dynamics.DataEntities.GetExportedPackageUrl"); + try + { + var requestUri = GetAosRequestUri("data/DataManagementDefinitionGroups/Microsoft.Dynamics.DataEntities.GetExportedPackageUrl"); - var parameters = new { executionId }; - string parametersJson = JsonConvert.SerializeObject(parameters, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto }); + var parameters = new { executionId }; + string parametersJson = JsonConvert.SerializeObject(parameters, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto }); - var response = await PostStringRequestAsync(requestUri, parametersJson); - string result = response.Content.ReadAsStringAsync().Result; - JObject jsonResponse = (JObject)JsonConvert.DeserializeObject(result); - string jvalue = jsonResponse["value"].ToString(); - return new Uri(jvalue); + var response = await PostStringRequestAsync(requestUri, parametersJson); + string result = response.Content.ReadAsStringAsync().Result; + JObject jsonResponse = (JObject)JsonConvert.DeserializeObject(result); + string jvalue = jsonResponse["value"].ToString(); + return new Uri(jvalue); + } + catch + { + return null; + } } /// @@ -312,10 +307,6 @@ namespace RecurringIntegrationsScheduler.Common.Helpers /// execution's summary page Url public async Task GetExecutionSummaryPageUrl(string executionId) { - //var requestUri = new UriBuilder(_settings.AosUri) - //{ - // Path = "data/DataManagementDefinitionGroups/Microsoft.Dynamics.DataEntities.GetExecutionSummaryPageUrl" - //}; var requestUri = GetAosRequestUri("data/DataManagementDefinitionGroups/Microsoft.Dynamics.DataEntities.GetExecutionSummaryPageUrl"); var parameters = new { executionId }; @@ -355,10 +346,6 @@ namespace RecurringIntegrationsScheduler.Common.Helpers /// public async Task ImportFromPackage(string packageUrl, string definitionGroupId, string executionId, bool execute, bool overwrite, string legalEntityId) { - //var requestUri = new UriBuilder(_settings.AosUri) - //{ - // Path = "data/DataManagementDefinitionGroups/Microsoft.Dynamics.DataEntities.ImportFromPackage" - //}; var requestUri = GetAosRequestUri("data/DataManagementDefinitionGroups/Microsoft.Dynamics.DataEntities.ImportFromPackage"); var parameters = new @@ -381,10 +368,6 @@ namespace RecurringIntegrationsScheduler.Common.Helpers /// public async Task DeleteExecutionHistoryJob(string executionId) { - //var requestUri = new UriBuilder(_settings.AosUri) - //{ - // Path = "data/DataManagementDefinitionGroups/Microsoft.Dynamics.DataEntities.DeleteExecutionHistoryJob" - //}; var requestUri = GetAosRequestUri("data/DataManagementDefinitionGroups/Microsoft.Dynamics.DataEntities.DeleteExecutionHistoryJob"); var parameters = new { executionId }; @@ -407,10 +390,6 @@ namespace RecurringIntegrationsScheduler.Common.Helpers /// export package url public async Task ExportToPackage(string definitionGroupId, string packageName, string executionId, string legalEntityId, bool reExecute = false) { - //var requestUri = new UriBuilder(_settings.AosUri) - //{ - // Path = "data/DataManagementDefinitionGroups/Microsoft.Dynamics.DataEntities.ExportToPackage" - //}; var requestUri = GetAosRequestUri("data/DataManagementDefinitionGroups/Microsoft.Dynamics.DataEntities.ExportToPackage"); var parameters = new @@ -437,10 +416,6 @@ namespace RecurringIntegrationsScheduler.Common.Helpers /// export package url public async Task ExportFromPackage(string packageUrl, string definitionGroupId, string executionId, bool execute, bool overwrite, string legalEntityId) { - //var requestUri = new UriBuilder(_settings.AosUri) - //{ - // Path = "data/DataManagementDefinitionGroups/Microsoft.Dynamics.DataEntities.ExportFromPackage" - //}; var requestUri = GetAosRequestUri("data/DataManagementDefinitionGroups/Microsoft.Dynamics.DataEntities.ExportFromPackage"); var parameters = new diff --git a/Job.Export/Export.cs b/Job.Export/Export.cs index 4114e87..58da131 100644 --- a/Job.Export/Export.cs +++ b/Job.Export/Export.cs @@ -155,7 +155,17 @@ namespace RecurringIntegrationsScheduler.Job if (executionStatus == "Succeeded" || executionStatus == "PartiallySucceeded") { - Uri packageUrl = await _httpClientHelper.GetExportedPackageUrl(executionId); + attempt = 0; + Uri packageUrl = null; + do //Potentially endless loop + { + attempt++; + System.Threading.Thread.Sleep(_settings.Interval); + packageUrl = await _httpClientHelper.GetExportedPackageUrl(executionId); + if (Log.IsDebugEnabled) + Log.Debug(string.Format(Resources.Job_0_Trying_to_get_exported_package_URL_Try_1, _context.JobDetail.Key, attempt)); + } + while (packageUrl == null); var response = await _httpClientHelper.GetRequestAsync(new UriBuilder(packageUrl).Uri, false); if (!response.IsSuccessStatusCode) diff --git a/Job.Export/Properties/Resources.Designer.cs b/Job.Export/Properties/Resources.Designer.cs index e515e16..5880d88 100644 --- a/Job.Export/Properties/Resources.Designer.cs +++ b/Job.Export/Properties/Resources.Designer.cs @@ -240,6 +240,15 @@ namespace RecurringIntegrationsScheduler.Job.Properties { } } + /// + /// Looks up a localized string similar to Job: {0} Trying to get exported package URL. Try: {1}. + /// + internal static string Job_0_Trying_to_get_exported_package_URL_Try_1 { + get { + return ResourceManager.GetString("Job_0_Trying_to_get_exported_package_URL_Try_1", resourceCulture); + } + } + /// /// Looks up a localized string similar to Job: {0} was paused because of an error.. /// diff --git a/Job.Export/Properties/Resources.resx b/Job.Export/Properties/Resources.resx index 65a9147..a2a3ec9 100644 --- a/Job.Export/Properties/Resources.resx +++ b/Job.Export/Properties/Resources.resx @@ -180,4 +180,7 @@ Job: {0} thrown an error. Exception : {1} + + Job: {0} Trying to get exported package URL. Try: {1} + \ No newline at end of file diff --git a/Scheduler/App.config b/Scheduler/App.config index ec47698..99b0d80 100644 --- a/Scheduler/App.config +++ b/Scheduler/App.config @@ -28,7 +28,7 @@ - + diff --git a/Scheduler/Forms/ExportJob.Designer.cs b/Scheduler/Forms/ExportJob.Designer.cs index 6cb5b6b..d8881aa 100644 --- a/Scheduler/Forms/ExportJob.Designer.cs +++ b/Scheduler/Forms/ExportJob.Designer.cs @@ -189,7 +189,7 @@ namespace RecurringIntegrationsScheduler.Forms 0, 0}); this.interval.Minimum = new decimal(new int[] { - 60, + 5, 0, 0, 0});