private void HandleException(ICollection <string> failedIds, List <StudentDocument> students)
        {
            try
            {
                students?.ForEach(x =>
                {
                    if (failedIds.Contains(x.Id))
                    {
                        if (x.NoOfRetry < _noOfRetries)
                        {
                            Logger.Warning($"Adding {x.Name} again to list. Current attempt {x.NoOfRetry}");

                            _redisService.AddToSet(x.Id, nameof(StudentDocument), x.NoOfRetry + 1);
                        }
                        else
                        {
                            Logger.Error($"Could not process {x.Id}. Sending it to DLQ");

                            _redisService.AddToSet(x.Id, nameof(StudentDocument) + "-failed");
                        }
                    }
                });
            }
            catch (Exception e)
            {
                // worst case scenario
                Logger.Error(e, "Could not add again students to redis set!");
            }
        }
示例#2
0
        private async Task SendList(SocketTextChannel channel)
        {
            var commands = new HashSet <string>();
            var all      = await _redis.GetSet("discord:bot:replies");

            if (all.Count == 0)
            {
                var replies = await _db.SiteConfig.Where(w => w.Key.Contains("discord:bot:reply:")).ToListAsync();

                commands = replies.Select(w => w.Key.Replace("discord:bot:reply:", "")).ToHashSet();
                foreach (var command in commands)
                {
                    await _redis.AddToSet("discord:bot:replies", command, TimeSpan.FromHours(1));
                }
            }
            else
            {
                commands = all;
            }

            commands.Add("verify");
            commands.Add("stats");

            var builder = new StringBuilder("Possible commands:").AppendLine();

            foreach (var command in commands)
            {
                builder.AppendLine($"!{command}");
            }

            await channel.SendMessageAsync(builder.ToString());
        }
        private void HandleInternal(string id)
        {
            var isElasticSearchSyncEnabled = _appSettings.Get <bool>(Constants.EnableElasticSearchSync);

            if (!isElasticSearchSyncEnabled)
            {
                Logger.Debug("Sync event is disabled via env settings!");

                return;
            }

            Task.Run(() =>
            {
                try
                {
                    _redisService.AddToSet(id, Constants.StudentDocument);

                    Logger.Debug($"StudentChange event triggered for {id}.");
                }
                catch (Exception e)
                {
                    Logger.Error(e, $"Could not handle the student changes for {id}.");
                }
            });
        }
        private void OnStudentChanged(object sender, RecordChangedEventArgs <StudentDocument> e)
        {
            StudentDocument changedEntity = e.Entity;

            Logger.Debug($"Change detected:{changedEntity.StudentId}");

            try
            {
                redisService.AddToSet(changedEntity.StudentId, "StudentDocument");
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "Can't handle changes for students");
            }
        }