Esempio n. 1
0
 private TaskSearchResponse FindTasks([NotNull] RtqMonitoringSearchRequest searchRequest)
 {
     if (searchRequest.Offset == null || searchRequest.Count == null)
     {
         throw new InvalidOperationException("Offset and Count should have value");
     }
     return(taskSearchClient.Search(CreateTaskSearchRequest(searchRequest), searchRequest.Offset.Value, searchRequest.Count.Value));
 }
Esempio n. 2
0
 private static TaskSearchRequest CreateTaskSearchRequest([NotNull] RtqMonitoringSearchRequest searchRequest)
 {
     return(new TaskSearchRequest
     {
         TaskStates = searchRequest.States?.Select(x => x.ToString()).ToArray(),
         TaskNames = searchRequest.Names,
         QueryString = string.IsNullOrWhiteSpace(searchRequest.QueryString) ? "*" : searchRequest.QueryString,
         FromTicksUtc = searchRequest.EnqueueTimestampRange.LowerBound.Ticks,
         ToTicksUtc = searchRequest.EnqueueTimestampRange.UpperBound.Ticks,
     });
 }
Esempio n. 3
0
        public Dictionary <string, TaskManipulationResult> CancelTasksBySearchQuery([NotNull] RtqMonitoringSearchRequest searchRequest)
        {
            var result = new Dictionary <string, TaskManipulationResult>();

            foreach (var taskId in FindAllTasks(searchRequest).Distinct())
            {
                var taskManipulationResult = taskManager.TryCancelTask(taskId);
                result.Add(taskId, taskManipulationResult);
            }
            return(result);
        }
Esempio n. 4
0
        private IEnumerable <string> FindAllTasks([NotNull] RtqMonitoringSearchRequest searchRequest)
        {
            const int batchSize         = 100;
            var       taskSearchRequest = CreateTaskSearchRequest(searchRequest);
            var       currentOffset     = 0;

            while (true)
            {
                var result = taskSearchClient.Search(taskSearchRequest, currentOffset, batchSize);
                if (result.Ids.Length == 0)
                {
                    yield break;
                }
                foreach (var id in result.Ids)
                {
                    yield return(id);
                }
                currentOffset += batchSize;
            }
        }
Esempio n. 5
0
        public RtqMonitoringSearchResults Search([NotNull] RtqMonitoringSearchRequest searchRequest)
        {
            if (searchRequest.EnqueueTimestampRange == null)
            {
                throw new InvalidOperationException("searchRequest.EnqueueTimestampRange is not set");
            }

            var searchResult  = FindTasks(searchRequest);
            var taskMetas     = taskManager.GetTaskMetas(searchResult.Ids);
            var taskListItems = new List <RtqMonitoringTaskMeta>();

            foreach (var taskId in searchResult.Ids)
            {
                if (taskMetas.TryGetValue(taskId, out var taskMeta))
                {
                    taskListItems.Add(taskMeta.ToMonitoringTaskMeta());
                }
            }
            return(new RtqMonitoringSearchResults
            {
                TotalCount = searchResult.TotalCount,
                TaskMetas = taskListItems.ToArray(),
            });
        }