public async Task <DeltaResponse> CalculateDifferenceAsync(GroupMembership membership, List <AzureADUser> membersFromDestinationGroup) { var deltaResponse = new DeltaResponse { IsDryRunSync = _isGraphUpdaterDryRunEnabled }; var fromto = $"to {membership.Destination}"; var changeTo = SyncStatus.Idle; var job = await _syncJobRepository.GetSyncJobAsync(membership.SyncJobPartitionKey, membership.SyncJobRowKey); SetupLoggingRepository(membership, job); if (job == null) { await _loggingRepository.LogMessageAsync(new LogMessage { Message = $"Sync job : Partition key {membership.SyncJobPartitionKey}, Row key {membership.SyncJobRowKey} was not found!", RunId = membership.RunId }); deltaResponse.GraphUpdaterStatus = GraphUpdaterStatus.Error; deltaResponse.SyncStatus = SyncStatus.Error; deltaResponse.IsDryRunSync = membership.MembershipObtainerDryRunEnabled || _isGraphUpdaterDryRunEnabled; return(deltaResponse); } var isDryRunSync = _loggingRepository.DryRun = job.IsDryRunEnabled || membership.MembershipObtainerDryRunEnabled || _isGraphUpdaterDryRunEnabled; await _loggingRepository.LogMessageAsync(new LogMessage { Message = $"The Dry Run Enabled configuration is currently set to {isDryRunSync}. We will not be syncing members if any of the 3 Dry Run Enabled configurations is set to True.", RunId = membership.RunId }); await _loggingRepository.LogMessageAsync(new LogMessage { Message = $"Processing sync job : Partition key {membership.SyncJobPartitionKey} , Row key {membership.SyncJobRowKey}", RunId = membership.RunId }); await _loggingRepository.LogMessageAsync(new LogMessage { Message = $"{job.TargetOfficeGroupId} job's status is {job.Status}.", RunId = membership.RunId }); var groupExistsResult = await _graphUpdaterService.GroupExistsAsync(membership.Destination.ObjectId, membership.RunId); if (!groupExistsResult.Result) { await _loggingRepository.LogMessageAsync(new LogMessage { Message = $"When syncing {fromto}, destination group {membership.Destination} doesn't exist. Not syncing and marking as error.", RunId = membership.RunId }); changeTo = SyncStatus.Error; } if (changeTo == SyncStatus.Idle) { var delta = await CalculateDeltaAsync(membership, fromto, membersFromDestinationGroup); var isInitialSync = job.LastRunTime == DateTime.FromFileTimeUtc(0); var threshold = isInitialSync ? new ThresholdResult() : await CalculateThresholdAsync(job, delta.Delta, delta.TotalMembersCount, membership.RunId); deltaResponse.MembersToAdd = delta.Delta.ToAdd; deltaResponse.MembersToRemove = delta.Delta.ToRemove; deltaResponse.SyncStatus = SyncStatus.Idle; deltaResponse.IsInitialSync = isInitialSync; deltaResponse.IsDryRunSync = isDryRunSync; deltaResponse.Requestor = job.Requestor; deltaResponse.SyncJobType = job.Type; deltaResponse.Timestamp = job.Timestamp; deltaResponse.GraphUpdaterStatus = GraphUpdaterStatus.Ok; if (threshold.IsThresholdExceeded) { deltaResponse.GraphUpdaterStatus = GraphUpdaterStatus.ThresholdExceeded; await SendThresholdNotificationAsync(threshold, job, membership.RunId); return(deltaResponse); } } if (changeTo == SyncStatus.Error) { return(new DeltaResponse { GraphUpdaterStatus = GraphUpdaterStatus.Error, SyncStatus = SyncStatus.Error, IsDryRunSync = isDryRunSync, }); } return(deltaResponse); }
public async Task <SyncJob> GetSyncJobAsync(string partitionKey, string rowKey) { return(await _syncJobRepository.GetSyncJobAsync(partitionKey, rowKey)); }