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

                return GetJobsWithProperties(
                    redis,
                    failedJobIds,
                    null,
                    new[] { "FailedAt", "ExceptionType", "ExceptionMessage", "ExceptionDetails", "State", "Reason" },
                    (job, jobData, state) => new FailedJobDto
                {
                    Job = job,
                    Reason = state[5],
                    FailedAt = JobHelper.DeserializeNullableDateTime(state[0]),
                    ExceptionType = state[1],
                    ExceptionMessage = state[2],
                    ExceptionDetails = state[3],
                    InFailedState = FailedState.StateName.Equals(state[4], StringComparison.OrdinalIgnoreCase)
                });
            }));
        }
Example #2
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());
            }));
        }
Example #3
0
        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)
                });
            }));
        }
Example #4
0
        public JobList <TagsSucceededJobDto> SucceededJobs(string tagName, int from, int count)
        {
            tagName = tagName.ToLower();
            return(UseConnection(redis =>
            {
                var succeededJobIds = redis
                                      .ListRange(GetRedisKey(RedisTagsKeyInfo.GetSucceededKey(tagName)), from, from + count - 1)
                                      .ToStringArray();

                return GetJobsWithProperties(
                    redis,
                    succeededJobIds,
                    null,
                    new[] { "SucceededAt", "PerformanceDuration", "Latency", "State", "Result" },
                    (job, jobData, state) => new TagsSucceededJobDto
                {
                    Duration = state[1] != null ? (long?)long.Parse(state[1]) : null,
                    Latency = state[2] != null ? (long?)long.Parse(state[2]) : null,
                    Job = job,
                    Result = state[4],
                    SucceededAt = JobHelper.DeserializeNullableDateTime(state[0]),
                    TotalDuration = state[1] != null && state[2] != null
                            ? (long?)long.Parse(state[1]) + (long?)long.Parse(state[2])
                            : null,
                    InSucceededState = SucceededState.StateName.Equals(state[3], StringComparison.OrdinalIgnoreCase)
                });
            }));
        }
Example #5
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 #6
0
        public long DeletedListCount([NotNull] string tagName)
        {
            if (tagName == null)
            {
                throw new ArgumentNullException(nameof(tagName));
            }

            return(UseConnection(redis => redis.ListLength(GetRedisKey(RedisTagsKeyInfo.GetDeletedKey(tagName)))));
        }
Example #7
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 #8
0
        public JobList <ScheduledJobDto> ScheduledJobs(string tagName, int from, int count)
        {
            return(UseConnection(redis =>
            {
                var scheduledJobs = redis
                                    .SortedSetRangeByRankWithScores(GetRedisKey(RedisTagsKeyInfo.GetScheduledKey(tagName)), from, from + count - 1)
                                    .ToList();

                if (scheduledJobs.Count == 0)
                {
                    return new JobList <ScheduledJobDto>(new List <KeyValuePair <string, ScheduledJobDto> >());
                }

                var jobs = new ConcurrentDictionary <string, List <string> >();
                var states = new ConcurrentDictionary <string, List <string> >();;

                var pipeline = redis.CreateBatch();
                var tasks = new Task[scheduledJobs.Count * 2];
                int i = 0;
                foreach (var scheduledJob in scheduledJobs)
                {
                    var jobId = scheduledJob.Element;
                    tasks[i] = pipeline.HashGetAsync(
                        GetRedisKey($"job:{jobId}"),
                        new RedisValue[] { "Type", "Method", "ParameterTypes", "Arguments" })
                               .ContinueWith(x => jobs.TryAdd(jobId, x.Result.ToStringArray().ToList()));
                    i++;
                    tasks[i] = pipeline.HashGetAsync(
                        GetRedisKey($"job:{jobId}:state"),
                        new RedisValue[] { "State", "ScheduledAt" })
                               .ContinueWith(x => states.TryAdd(jobId, x.Result.ToStringArray().ToList()));
                    i++;
                }

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

                return new JobList <ScheduledJobDto>(scheduledJobs
                                                     .Select(job => new KeyValuePair <string, ScheduledJobDto>(
                                                                 job.Element,
                                                                 new ScheduledJobDto
                {
                    EnqueueAt = JobHelper.FromTimestamp((long)job.Score),
                    Job = TryToGetJob(jobs[job.Element][0], jobs[job.Element][1], jobs[job.Element][2], jobs[job.Element][3]),
                    ScheduledAt =
                        states[job.Element].Count > 1
                                    ? JobHelper.DeserializeNullableDateTime(states[job.Element][1])
                                    : null,
                    InScheduledState =
                        ScheduledState.StateName.Equals(states[job.Element][0], StringComparison.OrdinalIgnoreCase)
                }))
                                                     .ToList());
            }));
        }
Example #9
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 #10
0
        public JobList <DeletedJobDto> DeletedJobs(string tagName, int from, int count)
        {
            return(UseConnection(redis =>
            {
                var deletedJobIds = redis
                                    .ListRange(GetRedisKey(RedisTagsKeyInfo.GetDeletedKey(tagName)), from, from + count - 1)
                                    .ToStringArray();

                return GetJobsWithProperties(
                    redis,
                    deletedJobIds,
                    null,
                    new[] { "DeletedAt", "State" },
                    (job, jobData, state) => new DeletedJobDto
                {
                    Job = job,
                    DeletedAt = JobHelper.DeserializeNullableDateTime(state[0]),
                    InDeletedState = DeletedState.StateName.Equals(state[1], StringComparison.OrdinalIgnoreCase)
                });
            }));
        }
Example #11
0
 public List <ServerTagsStatisticDto> MinuteFailedJobs(string[] servers, DateTime?startDate = null, DateTime?endDate = null)
 {
     endDate   = endDate.HasValue && endDate.Value > DateTime.Now.AddDays(-2) ? endDate.Value : DateTime.Now;
     startDate = startDate.HasValue && startDate.Value > DateTime.MinValue ? startDate.Value : endDate.Value.AddMinutes(-30);
     return(UseConnection(redis => GetMinuteTimelineStats(redis, servers, (server, date) => RedisTagsKeyInfo.GetStatsFailedMinuteKey(server, date), startDate.Value, endDate.Value)));
 }
Example #12
0
 public List <ServerTagsStatisticDto> HourlySucceededJobs(string[] servers, DateTime?startDate = null, DateTime?endDate = null)
 {
     endDate   = endDate.HasValue && endDate.Value > DateTime.Now.AddDays(-7) ? endDate.Value : DateTime.Now;
     startDate = startDate.HasValue && startDate.Value > DateTime.MinValue ? startDate.Value : endDate.Value.AddDays(-2);
     return(UseConnection(redis => GetHourlyTimelineStats(redis, servers, (server, date) => RedisTagsKeyInfo.GetStatsSucceededHourKey(server, date), startDate.Value, endDate.Value)));
 }
Example #13
0
 public List <ServerTagsStatisticDto> DateFailedJobs(string[] servers, string tagCode, DateTime?startDate = null, DateTime?endDate = null)
 {
     endDate   = endDate.HasValue && endDate.Value > DateTime.Today.AddDays(-30) ? endDate.Value : DateTime.Today;
     startDate = startDate.HasValue && startDate.Value > DateTime.MinValue ? startDate.Value : endDate.Value.AddDays(-15);
     return(UseConnection(redis => GetDailyTimelineStats(redis, servers, (server, date) => RedisTagsKeyInfo.GetStatsFailedDateKey(tagCode, server, date), startDate.Value, endDate.Value)));
 }
Example #14
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;
            }));
        }
Example #15
0
 public IDictionary <DateTime, long> MinuteFailedJobs(string tagCode, DateTime?startDate = null, DateTime?endDate = null)
 {
     endDate   = endDate.HasValue && endDate.Value > DateTime.Now.AddDays(-2) ? endDate.Value : DateTime.Now;
     startDate = startDate.HasValue && startDate.Value > DateTime.MinValue ? startDate.Value : endDate.Value.AddMinutes(-30);
     return(UseConnection(redis => GetMinuteTimelineStats(redis, x => RedisTagsKeyInfo.GetStatsFailedMinuteKey(tagCode, x), startDate.Value, endDate.Value)));
 }
Example #16
0
 public IDictionary <DateTime, long> HourlySucceededJobs(string tagCode, DateTime?startDate = null, DateTime?endDate = null)
 {
     endDate   = endDate.HasValue && endDate.Value > DateTime.Now.AddDays(-7) ? endDate.Value : DateTime.Now;
     startDate = startDate.HasValue && startDate.Value > DateTime.MinValue ? startDate.Value : endDate.Value.AddDays(-2);
     return(UseConnection(redis => GetHourlyTimelineStats(redis, x => RedisTagsKeyInfo.GetStatsSucceededHourKey(tagCode, x), startDate.Value, endDate.Value)));
 }
Example #17
0
 public IDictionary <DateTime, long> DateSucceededJobs(string tagCode, DateTime?startDate = null, DateTime?endDate = null)
 {
     endDate   = endDate.HasValue && endDate.Value > DateTime.Today.AddDays(-30) ? endDate.Value : DateTime.Today;
     startDate = startDate.HasValue && startDate.Value > DateTime.MinValue ? startDate.Value : endDate.Value.AddDays(-15);
     return(UseConnection(redis => GetDailyTimelineStats(redis, x => RedisTagsKeyInfo.GetStatsSucceededDateKey(tagCode, x), startDate.Value, endDate.Value)));
 }