Ejemplo n.º 1
0
        public IDictionary <string, int> GetJobStateCount(string[] tags, int maxTags = 50)
        {
            var monitoringApi = MonitoringApi;

            return(monitoringApi.UseConnection(connection =>
            {
                var succeededCount = 0L;
                var deletedCount = 0L;
                var failedCount = 0L;

                var pipeline = connection.CreateBatch();
                var tasks = new List <Task> {
                };
                foreach (var tag in tags)
                {
                    var tagCode = tag.Replace("tags:", string.Empty);
                    var task = pipeline.ListLengthAsync(GetRedisKey(RedisTagsKeyInfo.GetSucceededKey(tagCode)))
                               .ContinueWith(x =>
                    {
                        succeededCount += x.Result;
                    });
                    tasks.Add(task);

                    var deletedTask = pipeline.ListLengthAsync(GetRedisKey(RedisTagsKeyInfo.GetDeletedKey(tagCode)))
                                      .ContinueWith(x =>
                    {
                        deletedCount += x.Result;
                    });
                    tasks.Add(deletedTask);

                    var failedTask = pipeline.SortedSetLengthAsync(GetRedisKey(RedisTagsKeyInfo.GetFailedKey(tagCode)))
                                     .ContinueWith(x =>
                    {
                        failedCount += x.Result;
                    });
                    tasks.Add(failedTask);
                }
                pipeline.Execute();
                Task.WaitAll(tasks.ToArray());

                var result = new Dictionary <string, int> {
                };
                if (succeededCount > 0)
                {
                    result.Add("Succeeded", Convert.ToInt32(succeededCount));
                }

                if (failedCount > 0)
                {
                    result.Add("Failed", Convert.ToInt32(failedCount));
                }

                if (deletedCount > 0)
                {
                    result.Add("Deleted", Convert.ToInt32(deletedCount));
                }
                return result;
            }));
        }
Ejemplo n.º 2
0
        private int GetJobCount(IDatabase connection, string[] tags, string stateName)
        {
            var jobCount = 0L;

            var pipeline = connection.CreateBatch();
            var tasks    = new List <Task> {
            };

            foreach (var tag in tags)
            {
                var tagCode = tag.Replace("tags:", string.Empty);

                if (string.IsNullOrWhiteSpace(stateName) || stateName.ToLower() == "succeeded")
                {
                    var task = pipeline.ListLengthAsync(GetRedisKey(RedisTagsKeyInfo.GetSucceededKey(tagCode)))
                               .ContinueWith(x =>
                    {
                        jobCount += x.Result;
                    });
                    tasks.Add(task);
                }

                if (string.IsNullOrWhiteSpace(stateName) || stateName.ToLower() == "deleted")
                {
                    var deletedTask = pipeline.ListLengthAsync(GetRedisKey(RedisTagsKeyInfo.GetDeletedKey(tagCode)))
                                      .ContinueWith(x =>
                    {
                        jobCount += x.Result;
                    });
                    tasks.Add(deletedTask);
                }

                if (string.IsNullOrWhiteSpace(stateName) || stateName.ToLower() == "failed")
                {
                    var failedTask = pipeline.SortedSetLengthAsync(GetRedisKey(RedisTagsKeyInfo.GetFailedKey(tagCode)))
                                     .ContinueWith(x =>
                    {
                        jobCount += x.Result;
                    });
                    tasks.Add(failedTask);
                }
            }
            pipeline.Execute();
            Task.WaitAll(tasks.ToArray());

            return(Convert.ToInt32(jobCount));
        }
Ejemplo n.º 3
0
        private JobList <TDto> GetJobs <TDto>(IDatabase connection, int from, int count, string[] tags, string stateName, Func <Job, IReadOnlyList <string>, SafeDictionary <string, string>, TDto> selector)
        {
            var properties         = new string[] { "State", "CreatedAt" };
            var extendedProperties = properties.Concat(new[] { "Type", "Method", "ParameterTypes", "Arguments" }).ToRedisValues();
            var stateProperties    = new string[] { };

            var jobIdSource = new List <string> {
            };

            foreach (var tag in tags)
            {
                var tagCode = tag.Replace("tags:", string.Empty);
                if (string.IsNullOrWhiteSpace(stateName) || stateName.ToLower() == "succeeded")
                {
                    var succeededJobIdList = connection
                                             .ListRange(GetRedisKey(RedisTagsKeyInfo.GetSucceededKey(tagCode)))
                                             .ToStringArray();
                    jobIdSource.AddRange(succeededJobIdList);
                }
                if (string.IsNullOrWhiteSpace(stateName) || stateName.ToLower() == "deleted")
                {
                    var deletedJobIdList = connection
                                           .ListRange(GetRedisKey(RedisTagsKeyInfo.GetDeletedKey(tagCode)))
                                           .ToStringArray();
                    jobIdSource.AddRange(deletedJobIdList);
                }
                if (string.IsNullOrWhiteSpace(stateName) || stateName.ToLower() == "failed")
                {
                    var failedJobIdList = connection
                                          .SortedSetRangeByRankWithScores(GetRedisKey(RedisTagsKeyInfo.GetFailedKey(tagCode)), order: Order.Descending)
                                          .Select(x => x.Element.ToString())
                                          .ToArray();
                    jobIdSource.AddRange(failedJobIdList);
                }
            }
            var jobIds = jobIdSource.Distinct().Skip(from).Take(count).ToArray();

            return(GetJobsWithProperties(connection, jobIds, properties, stateProperties, selector));
        }