public async Task <ReturnQueryIndexDto> QueryJobIndexAsync(QueryJobIndexDto dto)
        {
            var resp = await SendRequestAsync <ReturnQueryIndexDto, QueryJobIndexDto>(HttpMethod.Post,
                                                                                      $"api/QueryIndex",
                                                                                      dto);

            if (resp.Result)
            {
                return(resp.Data);
            }
            throw new Exception($"{nameof(QueryJobIndexAsync)} failed {resp.Msg}");
        }
        public async Task <ReturnQueryIndexDto> QueryJobsAsync(QueryJobIndexDto dto)
        {
            if (dto.Start > dto.End)
            {
                throw new InvalidOperationException("the start date cannot be greater than the end date");
            }

            if (dto.PageNumber <= 0)
            {
                dto.PageNumber = 1;
            }

            if (dto.PageSize <= 0)
            {
                dto.PageSize = 10;
            }

            var timeIndices       = Helper.GetTimeIndexRange(dto.Start, dto.End);
            var result            = new ConcurrentDictionary <long, JobIndexInternal>();
            var queryIndicesBlock = new ActionBlock <string>(
                async index =>
            {
                var readOnlyGrainIndices =
                    await _client.GetGrain <IAggregateJobIndexGrain>(index).QueryAsync(dto.Predicate);
                foreach (var innerIndex in readOnlyGrainIndices)
                {
                    result[innerIndex.JobId] = innerIndex;
                }
            }, Helper.GetOutOfGrainExecutionOptions());

            foreach (var index in timeIndices)
            {
                await queryIndicesBlock.PostToBlockUntilSuccessAsync(index);
            }

            queryIndicesBlock.Complete();
            await queryIndicesBlock.Completion;

            return(new ReturnQueryIndexDto
            {
                Indices = _mapper.Map <List <JobIndex> >(result.Values
                                                         .OrderByDescending(s => s.JobId)
                                                         .Skip((dto.PageNumber - 1) * dto.PageNumber)
                                                         .Take(dto.PageSize)
                                                         .ToList()),
                IndexGrainHit = timeIndices.Count,
                TotalCount = result.Count
            });
        }
        public async Task <ReturnQueryIndexDto> QueryJobsAsync(QueryJobIndexDto dto)
        {
            if (dto.Start > dto.End)
            {
                throw new InvalidOperationException("the start date cannot be greater than the end date");
            }

            if (dto.PageNumber <= 0)
            {
                dto.PageNumber = 1;
            }

            if (dto.PageSize <= 0)
            {
                dto.PageSize = 10;
            }

            var timeIndices = Helper.GetTimeIndexRange(dto.Start, dto.End);
            var result      = new ConcurrentDictionary <long, JobIndexInternal>();

            await Helper.RunWithActionBlockAsync(timeIndices, async index =>
            {
                var indexCount = await _client.GetGrain <IAggregateJobIndexGrain>(index).GetRollingIndexCountAsync();
                var indexSeq   = Enumerable.Range(0, indexCount + 1).ToList();

                await Helper.RunWithActionBlockAsync(indexSeq, async shardIndex =>
                {
                    var grain = _client.GetGrain <IRollingJobIndexGrain>(Helper.GetRollingIndexId(index, shardIndex));
                    foreach (var item in await grain.QueryAsync(dto.Predicate))
                    {
                        result[item.JobId] = item;
                    }
                });
            });

            return(new ReturnQueryIndexDto
            {
                Indices = _mapper.Map <List <JobIndex> >(result.Values
                                                         .OrderByDescending(s => s.IndexTime)
                                                         .Skip((dto.PageNumber - 1) * dto.PageSize)
                                                         .Take(dto.PageSize)
                                                         .ToList()),
                IndexGrainHit = timeIndices.Count,
                TotalCount = result.Count
            });
        }
Example #4
0
 public async Task <ReturnDto <ReturnQueryIndexDto> > QueryJobIndicesAsync([FromBody] QueryJobIndexDto dto)
 {
     return(new ReturnDto <ReturnQueryIndexDto>(await _service.QueryJobsAsync(dto)));
 }
Example #5
0
 public abstract Task <ReturnQueryIndexDto> QueryJobIndexAsync(QueryJobIndexDto dto);