Beispiel #1
0
        private ActivityChildAgeAndGradeSyncOperation SyncChildAgeAndGradeData(ChildAgeAndGradeDeltaLogDto deltaResult, DateTime lastSuccessfulSyncDate)
        {
            var activity = new ActivityChildAgeAndGradeSyncOperation(_clock.UtcNow)
            {
                PreviousSyncDate = lastSuccessfulSyncDate,
                AgeAndGradeDelta = deltaResult
            };

            try
            {
                _logger.LogInformation("Starting MP contact age/grade count updates to HubSpot one-way sync operation...");
                activity.BulkUpdateSyncResult1000            = _contactSyncer.BulkSync(_dataPrep.Prep(_ministryPlatformContactRepository.GetAgeAndGradeGroupDataForContacts()), batchSize: 1000);
                activity.BulkUpdateSyncResult100             = _contactSyncer.BulkSync(_dataPrep.ToBulk(activity.BulkUpdateSyncResult1000.FailedBatches), batchSize: 100);
                activity.BulkUpdateSyncResult10              = _contactSyncer.BulkSync(_dataPrep.ToBulk(activity.BulkUpdateSyncResult100.FailedBatches), batchSize: 10);
                activity.RetryBulkUpdateAsSerialUpdateResult = _contactSyncer.SerialUpdate(_dataPrep.ToSerial(activity.BulkUpdateSyncResult10.FailedBatches));
                activity.SerialCreateResult = _contactSyncer.SerialCreate(activity.RetryBulkUpdateAsSerialUpdateResult.EmailAddressesDoNotExist.ToArray()); // in the event they don't yet exist but won't be picked up any other way b/c their kiddo count is the only thing to change

                return(activity);
            }
            catch (Exception exc)
            {
                _logger.LogError(CoreEvent.Exception, exc, "An exception occurred while syncing MP contact age & grade updates to HubSpot.");
                throw;
            }
            finally // *** ALWAYS *** capture the HubSpot API request count, even if an exception occurs
            {
                activity.Execution.FinishUtc = _clock.UtcNow;
                _jobRepository.PersistHubSpotApiDailyRequestCount(activity.HubSpotApiRequestCount, activity.Execution.StartUtc);
            }
        }
Beispiel #2
0
        private void Log(ChildAgeAndGradeDeltaLogDto result)
        {
            _logger.LogInformation($@"
ProcessedUtc: {result?.ProcessedUtc}
SyncCompletedUtc: {result?.SyncCompletedUtc}
Inserts: {result?.InsertCount}
Updates: {result?.UpdateCount}");
        }
 public ActivityChildAgeAndGradeCalculationOperation()
 {
     Execution        = new ExecutionTime();
     AgeGradeDeltaLog = new ChildAgeAndGradeDeltaLogDto();
 }
 public ActivityChildAgeAndGradeCalculationOperation(DateTime executionStartTime)
 {
     Execution        = new ExecutionTime(executionStartTime);
     AgeGradeDeltaLog = new ChildAgeAndGradeDeltaLogDto();
 }
Beispiel #5
0
        private void SetUpDefaults()
        {
            var utcNowMockDateTime = DateTime.Parse("2018-05-21T08:00:00"); // 4a "local"

            var ageGradeProcessDate = DateTime.Parse("2018-05-21 12:00:00AM");
            var registrationDate    = DateTime.Parse("2018-05-21 1:00:00AM");
            var coreUpdateDate      = DateTime.Parse("2018-05-21 2:00:00AM");
            var ageGradeSyncDate    = DateTime.Parse("2018-05-21 3:00:00AM");
            var operationDates      = new OperationDates
            {
                RegistrationSyncDate   = registrationDate,
                CoreUpdateSyncDate     = coreUpdateDate,
                AgeAndGradeProcessDate = ageGradeProcessDate,
                AgeAndGradeSyncDate    = ageGradeSyncDate
            };

            var initialChildAgeGradeDto = new ChildAgeAndGradeDeltaLogDto
            {
                InsertCount      = 20,
                UpdateCount      = 2,
                ProcessedUtc     = DateTime.Parse("2018-05-22 12:00:00AM"),
                SyncCompletedUtc = null
            };

            var finalChildAgeGradeDto = new ChildAgeAndGradeDeltaLogDto
            {
                InsertCount      = 20,
                UpdateCount      = 2,
                ProcessedUtc     = DateTime.Parse("2018-05-22 12:00:00AM"),
                SyncCompletedUtc = DateTime.Parse("2018-05-22 03:00:00AM")
            };

            var ageGradeGroups = new List <AgeAndGradeGroupCountsForMpContactDto>();

            _mpContactRepoMock.Setup(repo => repo.CalculateAndPersistKidsClubAndStudentMinistryAgeAndGradeDeltas()).Returns(initialChildAgeGradeDto);
            _mpContactRepoMock.Setup(repo => repo.GetAgeAndGradeGroupDataForContacts()).Returns(ageGradeGroups);
            _mpContactRepoMock.Setup(repo => repo.SetChildAgeAndGradeDeltaLogSyncCompletedUtcDate()).Returns(finalChildAgeGradeDto.SyncCompletedUtc ?? default(DateTime));
            _mpContactRepoMock.Setup(repo => repo.GetNewlyRegisteredContacts(operationDates.RegistrationSyncDate)).Returns(new List <NewlyRegisteredMpContactDto>());
            _mpContactRepoMock.Setup(repo => repo.GetAuditedContactUpdates(operationDates.CoreUpdateSyncDate)).Returns(new Dictionary <string, List <CoreUpdateMpContactDto> >());
            _hubSpotSyncerMock.Setup(syncer => syncer.BulkSync(It.IsAny <BulkHubSpotContact[]>(), 1000)).Returns(new BulkSyncResult());
            _hubSpotSyncerMock.Setup(syncer => syncer.BulkSync(It.IsAny <BulkHubSpotContact[]>(), 100)).Returns(new BulkSyncResult());
            _hubSpotSyncerMock.Setup(syncer => syncer.BulkSync(It.IsAny <BulkHubSpotContact[]>(), 10)).Returns(new BulkSyncResult());
            _hubSpotSyncerMock.Setup(syncer => syncer.SerialCreate(It.IsAny <SerialHubSpotContact[]>())).Returns(new SerialSyncResult());
            _hubSpotSyncerMock.Setup(syncer => syncer.SerialUpdate(It.IsAny <SerialHubSpotContact[]>())).Returns(new SerialSyncResult());
            _hubSpotSyncerMock.Setup(syncer => syncer.ReconcileConflicts(It.IsAny <SerialHubSpotContact[]>())).Returns(new SerialSyncResult());
            _clockMock.Setup(clock => clock.UtcNow).Returns(utcNowMockDateTime);
            _configSvcMock.Setup(svc => svc.GetCurrentActivityProgress()).Returns(new ActivityProgress {
                ActivityState = ActivityState.Idle
            });
            _configSvcMock.Setup(svc => svc.GetLastSuccessfulOperationDates()).Returns(operationDates);
            _configSvcMock.Setup(svc => svc.PersistActivity()).Returns(true);
            _jobRepoMock.Setup(repo => repo.PersistActivityProgress(It.IsAny <ActivityProgress>()));
            _jobRepoMock.Setup(repo => repo.PersistLastSuccessfulOperationDates(It.IsAny <OperationDates>())).Returns <OperationDates>(x => x);
            _jobRepoMock.Setup(repo => repo.PersistHubSpotApiDailyRequestCount(It.IsAny <int>(), It.IsAny <DateTime>()));
            _jobRepoMock.Setup(repo => repo.PersistActivity(It.IsAny <Activity>()));
            _dataPrepMock.Setup(prep => prep.Prep(It.IsAny <IDictionary <string, List <CoreUpdateMpContactDto> > >())).Returns(new SerialHubSpotContact[0]);
            _dataPrepMock.Setup(prep => prep.Prep(It.IsAny <List <AgeAndGradeGroupCountsForMpContactDto> >())).Returns(new BulkHubSpotContact[0]);
            _dataPrepMock.Setup(prep => prep.Prep(It.IsAny <List <NewlyRegisteredMpContactDto> >())).Returns(new SerialHubSpotContact[0]);
            _dataPrepMock.Setup(prep => prep.ToBulk(It.IsAny <List <BulkSyncFailure> >())).Returns(new BulkHubSpotContact[0]);
            _dataPrepMock.Setup(prep => prep.ToSerial(It.IsAny <List <BulkSyncFailure> >())).Returns(new SerialHubSpotContact[0]);
            _activityCleanerMock.Setup(activityCleaner => activityCleaner.CleanUp(It.IsAny <IActivity>()));
        }