Пример #1
0
        public async Task <int> SyncPersonsWithTeams(ILog logger, bool pushEvenIfNotPersonExistsOnIndex = false)
        {
            var allSurveillanceItems = GetAllSurveillanceItems()
                                       .Where(person => !string.IsNullOrEmpty(person.CommonIdentifier))
                                       .ToList();

            var allWithTeams = (await _index.GetCompleteSet("", "teams/any()")).Where(x => x.Teams != null & x.Teams.Any()).ToDictionary(x => x.CommonIdentifier, y => y);

            var missingOnIndex = allSurveillanceItems
                                 .Where(x => !string.IsNullOrEmpty(x.CommonIdentifier) && !allWithTeams.ContainsKey(x.CommonIdentifier))
                                 .ToList();

            var pushThisBatch = new Dictionary <string, TModel>();

            foreach (var missedItem in missingOnIndex)
            {
                var itemOnIndex = await _index.GetByKey(missedItem.CommonIdentifier, false);

                if (itemOnIndex != null)
                {
                    await _index.AddToPropertyList(missedItem.CommonIdentifier, "Teams", missedItem.TeamProjectInt.ToString());
                }
                else
                {
                    if (pushEvenIfNotPersonExistsOnIndex)
                    {
                        if (pushThisBatch.ContainsKey(missedItem.CommonIdentifier))
                        {
                            pushThisBatch[missedItem.CommonIdentifier].Teams.Add(missedItem.TeamProjectInt.ToString());
                        }
                        else
                        {
                            pushThisBatch.Add(missedItem.CommonIdentifier, new TModel
                            {
                                CommonIdentifier = missedItem.CommonIdentifier,
                                Teams            = new string[] { missedItem.TeamProjectInt.ToString() }
                            });
                        }
                    }
                    else
                    {
                        logger.Warn($"Item with commonidentifier {missedItem.CommonIdentifier} was missing on index, but couldnt find this entry on the index. Continuing");
                    }
                }
            }

            if (pushThisBatch.Any())
            {
                await _index.MergeOrUploadBatch(pushThisBatch.Values.ToArray());
            }

            return(missingOnIndex.Count);
        }
Пример #2
0
        public async Task <bool> TryPush1000(T[] thisSet, IAzureSearch <T> myClient, ILog log, bool removeOldValues = false)
        {
            bool uploaded = false;
            int  retries  = 10;

            while (!uploaded)
            {
                var st = Stopwatch.StartNew();
                retries--;
                try
                {
                    await(removeOldValues ? myClient.UploadBatch(thisSet) : myClient.MergeOrUploadBatch(thisSet));
                    await Task.Delay(200);

                    uploaded = true;
                }
                catch (Exception e)
                {
                    st.Stop();
                    var str = $"While uploading, got exception after {st.Elapsed.Minutes} minutes: {e.Message} Stack {e.StackTrace}";
                    if (e.InnerException != null)
                    {
                        str += ". InnerException.message=" + e.InnerException.Message + ", InnerException.StackTrace=" + e.InnerException.StackTrace;
                    }
                    log?.Error(str);
                    if (retries == 0)
                    {
                        log.Error("Exiting after 10 tries");
                        Quit = true;
                        return(false);
                    }

                    log?.Info("Retrying");
                    myClient = GetAzureSearch();

                    await Task.Delay(3000);
                }
            }

            return(true);
        }