public JobList <EnqueuedJobDto> EnqueuedJobs([NotNull] string tagName, int from, int count) { if (tagName == null) { throw new ArgumentNullException(nameof(tagName)); } return(UseConnection(redis => { var jobIds = redis .SortedSetRangeByRankWithScores(GetRedisKey(RedisTagsKeyInfo.GetEnqueuedKey(tagName)), from, from + count - 1, order: Order.Descending) .Select(x => x.Element.ToString()) .ToArray(); return GetJobsWithProperties( redis, jobIds, new[] { "State" }, new[] { "EnqueuedAt", "State" }, (job, jobData, state) => new EnqueuedJobDto { Job = job, State = jobData[0], EnqueuedAt = JobHelper.DeserializeNullableDateTime(state[0]), InEnqueuedState = jobData[0].Equals(state[1], StringComparison.OrdinalIgnoreCase) }); })); }
public long EnqueuedCount([NotNull] string tagName) { if (tagName == null) { throw new ArgumentNullException(nameof(tagName)); } return(UseConnection(redis => redis.SortedSetLength(GetRedisKey(RedisTagsKeyInfo.GetEnqueuedKey(tagName))))); }
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; })); }
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; })); }