private JobList <MatchingJobDto> GetJobs(RedisTagsMonitoringApi monitoringApi, DatabaseWrapper redis, int from, int count, string[] tags, string stateName, Func <RedisJob, Job, SafeDictionary <string, string>, MatchingJobDto> selector) { var redisKeys = tags.Select(t => string.IsNullOrEmpty(stateName) ? $"{t}" : $"{t}:{stateName.ToLower()}") .ToArray(); List <string> jobIds; if (redisKeys.Length <= 1) { jobIds = redis.SortedSetRangeByScore(redisKeys.First(), from, count).ToList(); } else { var tempKey = $"tags:job-{stateName.ToLower()}-{Guid.NewGuid():N}"; redis.SortedSetCombineAndStore(tempKey, redisKeys); jobIds = redis.SortedSetRangeByScore(tempKey, from, count).ToList(); redis.KeyDelete(tempKey); } return(monitoringApi.GetJobsWithProperties(jobIds, new[] { "State", "CreatedAt" }, new[] { "EnqueuedAt", "FailedAt", "ScheduledAt", "SucceededAt", "DeletedAt" }, (method, job, state) => { var redisJob = new RedisJob { StateName = job[0], CreatedAt = JobHelper.DeserializeDateTime(job[1]), StateData = new Dictionary <string, string> { { "EnqueuedAt", state[0] }, { "FailedAt", state[1] }, { "ScheduledAt", state[2] }, { "SucceededAt", state[3] }, { "DeletedAt", state[4] } } }; return selector(redisJob, method, new SafeDictionary <string, string>(redisJob.StateData, StringComparer.InvariantCultureIgnoreCase)); })); }
public RedisTagsServiceStorage(RedisStorageOptions options) { MonitoringApi = new RedisTagsMonitoringApi(JobStorage.Current.GetMonitoringApi(), options); }