Exemplo n.º 1
0
        public TagsStatisticVM GetStatistics([NotNull] string tagName)
        {
            tagName = tagName.ToLower();
            return(UseConnection(redis =>
            {
                var stats = new TagsStatisticVM {
                };

                var pipeline = redis.CreateBatch();
                var tasks = new Task[10];

                tasks[0] = pipeline.SortedSetLengthAsync(GetRedisKey(RedisTagsKeyInfo.GetEnqueuedKey(tagName)))
                           .ContinueWith(x => stats.Enqueued = x.Result);

                tasks[1] = pipeline.SortedSetLengthAsync(GetRedisKey(RedisTagsKeyInfo.GetScheduledKey(tagName)))
                           .ContinueWith(x => stats.Scheduled = x.Result);

                tasks[2] = pipeline.SortedSetLengthAsync(GetRedisKey(RedisTagsKeyInfo.GetProcessingKey(tagName)))
                           .ContinueWith(x => stats.Processing = x.Result);

                tasks[3] = pipeline.StringGetAsync(GetRedisKey(RedisTagsKeyInfo.GetStatsSucceededKey(tagName)))
                           .ContinueWith(x => stats.Succeeded = long.Parse(x.Result.HasValue ? (string)x.Result : "0"));

                tasks[4] = pipeline.SortedSetLengthAsync(GetRedisKey(RedisTagsKeyInfo.GetFailedKey(tagName)))
                           .ContinueWith(x => stats.Failed = x.Result);

                tasks[5] = pipeline.StringGetAsync(GetRedisKey(RedisTagsKeyInfo.GetStatsDeletedKey(tagName)))
                           .ContinueWith(x => stats.Deleted = long.Parse(x.Result.HasValue ? (string)x.Result : "0"));

                tasks[6] = pipeline.SortedSetLengthAsync(GetRedisKey(RedisTagsKeyInfo.GetAwaitingKey(tagName)))
                           .ContinueWith(x => stats.Awaiting = x.Result);

                tasks[7] = pipeline.SortedSetLengthAsync(GetRedisKey(RedisTagsKeyInfo.GetRetryKey(tagName)))
                           .ContinueWith(x => stats.Retries = x.Result);

                tasks[8] = pipeline.SetLengthAsync(GetRedisKey("servers"))
                           .ContinueWith(x => stats.Servers = x.Result);

                tasks[9] = pipeline.SortedSetLengthAsync(GetRedisKey(RedisTagsKeyInfo.GetRecurringJobKey(tagName)))
                           .ContinueWith(x => stats.Recurring = x.Result);


                pipeline.Execute();
                Task.WaitAll(tasks);

                return stats;
            }));
        }
Exemplo n.º 2
0
        public List <TagsStatisticVM> GetStatisticsSummary(string[] tags)
        {
            return(UseConnection(redis =>
            {
                var result = new List <TagsStatisticVM> {
                };

                var pipeline = redis.CreateBatch();
                var tasks = new Task[tags.Length * 11];

                var index = 0;
                foreach (var tagName in tags)
                {
                    var stats = new TagsStatisticVM
                    {
                        TagCode = tagName
                    };
                    tasks[index++] = pipeline.SortedSetLengthAsync(GetRedisKey(RedisTagsKeyInfo.GetEnqueuedKey(tagName)))
                                     .ContinueWith(x => stats.Enqueued = x.Result);

                    tasks[index++] = pipeline.SortedSetLengthAsync(GetRedisKey(RedisTagsKeyInfo.GetScheduledKey(tagName)))
                                     .ContinueWith(x => stats.Scheduled = x.Result);

                    tasks[index++] = pipeline.SortedSetLengthAsync(GetRedisKey(RedisTagsKeyInfo.GetProcessingKey(tagName)))
                                     .ContinueWith(x => stats.Processing = x.Result);

                    tasks[index++] = pipeline.StringGetAsync(GetRedisKey(RedisTagsKeyInfo.GetStatsSucceededKey(tagName)))
                                     .ContinueWith(x => stats.Succeeded = long.Parse(x.Result.HasValue ? (string)x.Result : "0"));

                    tasks[index++] = pipeline.SortedSetLengthAsync(GetRedisKey(RedisTagsKeyInfo.GetFailedKey(tagName)))
                                     .ContinueWith(x => stats.Failed = x.Result);

                    tasks[index++] = pipeline.StringGetAsync(GetRedisKey(RedisTagsKeyInfo.GetStatsDeletedKey(tagName)))
                                     .ContinueWith(x => stats.Deleted = long.Parse(x.Result.HasValue ? (string)x.Result : "0"));

                    tasks[index++] = pipeline.SortedSetLengthAsync(GetRedisKey(RedisTagsKeyInfo.GetAwaitingKey(tagName)))
                                     .ContinueWith(x => stats.Awaiting = x.Result);

                    tasks[index++] = pipeline.SortedSetLengthAsync(GetRedisKey(RedisTagsKeyInfo.GetRetryKey(tagName)))
                                     .ContinueWith(x => stats.Retries = x.Result);

                    tasks[index++] = pipeline.StringGetAsync(GetRedisKey(RedisTagsKeyInfo.GetStatsSucceededDateKey(tagName, DateTime.Today)))
                                     .ContinueWith(x => stats.Today = long.Parse(x.Result.HasValue ? (string)x.Result : "0"));

                    tasks[index++] = pipeline.StringGetAsync(GetRedisKey(RedisTagsKeyInfo.GetStatsSucceededHourKey(tagName, DateTime.Now.AddHours(-1))))
                                     .ContinueWith(x => stats.LastHour = long.Parse(x.Result.HasValue ? (string)x.Result : "0"));

                    tasks[index++] = pipeline.SortedSetLengthAsync(GetRedisKey(RedisTagsKeyInfo.GetRecurringJobKey(tagName)))
                                     .ContinueWith(x =>
                    {
                        stats.Recurring = x.Result;
                    });

                    result.Add(stats);
                }


                pipeline.Execute();
                Task.WaitAll(tasks);

                return result;
            }));
        }