private async Task UpdateSoaRelatedPropertiesAsync(CloudJob sessionJob, Dictionary <string, object> properties) { try { Dictionary <string, string> metaDic = new Dictionary <string, string>(); var metadata = sessionJob.Metadata; if (metadata != null) { foreach (var item in metadata) { metaDic[item.Name] = item.Value; } } foreach (KeyValuePair <string, object> pair in properties) { TraceHelper.TraceEvent(TraceEventType.Verbose, "[AzureBatchSchedulerDelegation] .UpdateSoaRelatedProperties: Job custom property {0}={1}", pair.Key, pair.Value); if (pair.Value != null) { if (!SchedulerDelegationCommon.PropToEnvMapping.TryGetValue(pair.Key, out var envName)) { envName = pair.Key; } if (pair.Value != null) { metaDic[envName] = pair.Value.ToString(); TraceHelper.TraceEvent( TraceEventType.Verbose, "[AzureBatchSchedulerDelegation] .UpdateSoaRelatedProperties: Set job custom property {0}={1}", envName, pair.Value); } } } sessionJob.Metadata = metaDic.Select(p => new MetadataItem(p.Key, p.Value)).ToList(); int retry = 3; while (retry > 0) { try { await sessionJob.CommitChangesAsync().ConfigureAwait(false); TraceHelper.TraceEvent(TraceEventType.Information, "[AzureBatchSchedulerDelegation] .UpdateSoaRelatedProperties: Commit service job."); } catch (BatchException e) { var reqInfo = e.RequestInformation; if (reqInfo != null && reqInfo.HttpStatusCode == HttpStatusCode.Conflict) { TraceHelper.TraceEvent(TraceEventType.Warning, "[AzureBatchSchedulerDelegation] Conflict when commit service job property change: {0}", reqInfo.HttpStatusMessage); return; } else { TraceHelper.TraceEvent(TraceEventType.Warning, "[AzureBatchSchedulerDelegation] Conflict when commit service job property change: {0}", e.ToString()); throw; } } catch (Exception e) { TraceHelper.TraceEvent(TraceEventType.Warning, "[AzureBatchSchedulerDelegation] Failed to commit service job property change: {0}\nRetryCount = {1}", e, retry); await Task.Delay(TimeSpan.FromMilliseconds(100)).ConfigureAwait(false); } finally { retry--; } } } catch (Exception ex) { TraceHelper.TraceEvent(TraceEventType.Warning, "[AzureBatchSchedulerDelegation] Failed to update soa properties, {0}", ex.ToString()); throw; } }