Beispiel #1
0
        public JobList <ProcessingJobDto> ProcessingJobs(string tagName, int from, int count)
        {
            return(UseConnection(redis =>
            {
                var jobIds = redis
                             .SortedSetRangeByRankWithScores(GetRedisKey(RedisTagsKeyInfo.GetProcessingKey(tagName)), from, from + count - 1)
                             .Select(x => x.Element.ToString())
                             .ToArray();

                return new JobList <ProcessingJobDto>(GetJobsWithProperties(redis,
                                                                            jobIds,
                                                                            null,
                                                                            new[] { "StartedAt", "ServerName", "ServerId", "State" },
                                                                            (job, jobData, state) => new ProcessingJobDto
                {
                    ServerId = state[2] ?? state[1],
                    Job = job,
                    StartedAt = JobHelper.DeserializeNullableDateTime(state[0]),
                    InProcessingState = ProcessingState.StateName.Equals(
                        state[3], StringComparison.OrdinalIgnoreCase),
                })
                                                      .Where(x => x.Value.ServerId != null)
                                                      .OrderBy(x => x.Value.StartedAt).ToList());
            }));
        }
Beispiel #2
0
        public long ProcessingCount([NotNull] string tagName)
        {
            if (tagName == null)
            {
                throw new ArgumentNullException(nameof(tagName));
            }

            return(UseConnection(redis => redis.SortedSetLength(GetRedisKey(RedisTagsKeyInfo.GetProcessingKey(tagName)))));
        }
Beispiel #3
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;
            }));
        }
Beispiel #4
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;
            }));
        }