protected override void Execute() { var chunkSize = int.Parse(ConfigurationManager.AppSettings["INDEX_CHUNK_SIZE"]); GetIndexingDataResponce responce = accountService.GetIndexingData(new GetIndexingDataRequest() { ChunkSize = chunkSize }); while (true && responce.IndexingData.IsAny()) { try { Logger.Current.Informational("Entering into Indexing processor"); foreach (var data in responce.IndexingData) { try { Logger.Current.Informational("Application", data.EntityIDs != null && data.EntityIDs.Any() ? "Count00==" + data.EntityIDs.Count().ToString() + data.IndexType : "Empty Index Count00=" + data.IndexType.ToString()); IEnumerable <int> Ids = data.Ids.Select(s => s.Key); if (Ids != null && Ids.IsAny()) { switch ((IndexType)data.IndexType) { case IndexType.Contacts: contactService.ContactIndexing(new ContactIndexingRequest() { ContactIds = data.EntityIDs, Ids = data.Ids }); break; case IndexType.Campaigns: campaignService.CampaignIndexing(new CampaignIndexingRequest() { CampaignIds = data.EntityIDs }); break; case IndexType.Opportunity: opportunityService.OpportunityIndexing(new OpportunityIndexingRequest() { OpportunityIds = data.EntityIDs }); break; case IndexType.Forms: formService.FormIndexing(new FormIndexingRequest() { FormIds = data.EntityIDs }); break; case IndexType.Tags: tagService.TagIndexing(new TagIndexingRequest() { TagIds = data.EntityIDs }); break; case IndexType.Contacts_Delete: contactService.RemoveFromElastic(new RemoveFromElasticRequest() { ContactIds = data.EntityIDs }); break; default: break; } accountService.UpdateIndexingStatus(new UpdateIndexingStatusRequest() { ReferenceIds = data.ReferenceIDs, Status = 2 }); } } catch (Exception e) { ExceptionHandler.Current.HandleException(e, DefaultExceptionPolicies.LOG_ONLY_POLICY); if (data.EntityIDs != null && data.EntityIDs.IsAny()) { accountService.UpdateIndexingStatus(new UpdateIndexingStatusRequest() { ReferenceIds = data.ReferenceIDs, Status = 3 }); } } } } catch (Exception ex) { ExceptionHandler.Current.HandleException(ex, DefaultExceptionPolicies.LOG_ONLY_POLICY); } responce = accountService.GetIndexingData(new GetIndexingDataRequest() { ChunkSize = chunkSize }); if (responce.IndexingData.IsAny() == false) { break; } } }
protected override void ExecuteInternal(IJobExecutionContext context) { var indexingRequests = _accountService .GetIndexingData(new GetIndexingDataRequest { ChunkSize = _jobConfig.IndexChunkSize }) .IndexingData .ToArray(); if (!indexingRequests.IsAny()) { return; } Log.Informational("Entering into Indexing processor"); foreach (var indexingRequest in indexingRequests) { try { Log.Informational("Application", indexingRequest?.EntityIDs.Any() ?? false ? "Count00==" + indexingRequest.EntityIDs.Count() + indexingRequest.IndexType : "Empty Index Count00=" + indexingRequest.IndexType); var ids = indexingRequest.Ids.Select(s => s.Key); if (ids.IsAny()) { switch ((IndexType)indexingRequest.IndexType) { case IndexType.Contacts: _contactService.ContactIndexing(new ContactIndexingRequest { ContactIds = indexingRequest.EntityIDs, Ids = indexingRequest.Ids }); break; case IndexType.Campaigns: _campaignService.CampaignIndexing(new CampaignIndexingRequest { CampaignIds = indexingRequest.EntityIDs }); break; case IndexType.Opportunity: _opportunityService.OpportunityIndexing(new OpportunityIndexingRequest { OpportunityIds = indexingRequest.EntityIDs }); break; case IndexType.Forms: _formService.FormIndexing(new FormIndexingRequest { FormIds = indexingRequest.EntityIDs }); break; case IndexType.Tags: _tagService.TagIndexing(new TagIndexingRequest { TagIds = indexingRequest.EntityIDs }); break; case IndexType.Contacts_Delete: _contactService.RemoveFromElastic(new RemoveFromElasticRequest { ContactIds = indexingRequest.EntityIDs }); break; } _accountService.UpdateIndexingStatus(new UpdateIndexingStatusRequest { ReferenceIds = indexingRequest.ReferenceIDs, Status = IndexingStatus.Success }); } } catch (Exception ex) { if (indexingRequest?.EntityIDs?.IsAny() ?? false) { _accountService.UpdateIndexingStatus(new UpdateIndexingStatusRequest { ReferenceIds = indexingRequest.ReferenceIDs, Status = IndexingStatus.Failed }); } ExceptionHandler.Current.HandleException(ex, DefaultExceptionPolicies.LOG_ONLY_POLICY); } } }