Example #1
0
        public JobList <RetriesJobDto> RetriesJobs(string tagName, int from, int count)
        {
            return(UseConnection(redis =>
            {
                var retriesJobIds = redis
                                    .SortedSetRangeByRankWithScores(GetRedisKey(RedisTagsKeyInfo.GetRetryKey(tagName)), from, from + count - 1, order: Order.Descending)
                                    .Select(x => x.Element.ToString())
                                    .ToArray();

                return GetJobsWithProperties(
                    redis,
                    retriesJobIds,
                    new[] { "CreatedAt", "RetryCount" },
                    new[] { "State", "Reason", "EnqueueAt" },
                    (job, jobData, state) => new RetriesJobDto
                {
                    Job = job,
                    Reason = state[1],
                    State = state[0],
                    EnqueueAt = JobHelper.DeserializeNullableDateTime(state[2]),
                    CreatedAt = JobHelper.DeserializeDateTime(jobData[0]),
                    RetryCount = Convert.ToInt32(jobData[1])
                });
            }));
        }
Example #2
0
        public long RetriesCount([NotNull] string tagName)
        {
            if (tagName == null)
            {
                throw new ArgumentNullException(nameof(tagName));
            }

            return(UseConnection(redis => redis.SortedSetLength(GetRedisKey(RedisTagsKeyInfo.GetRetryKey(tagName)))));
        }
Example #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;
            }));
        }
Example #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;
            }));
        }