예제 #1
0
        public async Task <JobEntity> AddNewJobAsync(AddJobDto dto)
        {
            var jobId = dto.JobId ?? await _client.GetGrain <IJobIdGrain>(Constants.JobIdGrainDefaultName).GetNewIdAsync();

            return(_mapper.Map <JobEntity>(await _client.GetGrain <IJobGrain>(jobId)
                                           .AddJobAsync(dto)));
        }
예제 #2
0
 public AddJobDtoInternal(AddJobDto dto)
 {
     JobName     = dto.JobName;
     ParentJobId = dto.ParentJobId;
     Tags        = dto.Tags;
     CreatedBy   = dto.CreatedBy;
     Options     = dto.Options;
 }
예제 #3
0
        public async Task <JobEntity> AddNewJobAsync(AddJobDto dto, Guid bufferId)
        {
            RequestContext.Set(Constants.BufferIdKey, bufferId);
            var jobId = dto.JobId ??
                        await _client.GetGrain <IJobIdGrain>(Constants.JobIdGrainDefaultName).GetNewIdAsync();

            return(_mapper.Map <JobEntity>(await _client.GetGrain <IJobGrainInMem>(jobId)
                                           .AddJobAsync(dto)));
        }
        public async Task <JobEntity> CreateNewJobAsync(AddJobDto dto)
        {
            var resp = await SendRequestAsync <JobEntity, AddJobDto>(HttpMethod.Post,
                                                                     $"api/jobTracker/new", dto);

            if (resp.Result)
            {
                return(resp.Data);
            }
            throw new Exception($"{nameof(CreateNewJobAsync)} failed {resp.Msg}");
        }
예제 #5
0
        internal override async Task <JobEntity> CreateNewJobWithBufferAsync(AddJobDto dto, Guid bufferId)
        {
            var resp = await SendRequestAsync <JobEntity, AddJobDto>(HttpMethod.Post,
                                                                     $"api/bufferManager/{bufferId}/job/new", dto);

            if (resp.Result)
            {
                return(resp.Data);
            }

            throw new Exception($"{nameof(CreateNewJobWithBufferAsync)} failed {resp.Msg}");
        }
예제 #6
0
        public async Task <JobEntityState> AddJobAsync(AddJobDto dto)
        {
            var addJobDto = new AddJobDtoInternal(dto);

            if (State.CurrentJobState != JobState.WaitingForActivation)
            {
                throw new InvalidOperationException($"job id duplicate: {this.GetPrimaryKeyLong()}");
            }

            const JobState state = JobState.WaitingToRun;
            var            jobId = this.GetPrimaryKeyLong();

            State.JobId       = jobId;
            State.ParentJobId = addJobDto.ParentJobId;
            State.CreateBy    = addJobDto.CreatedBy;
            State.Tags        = addJobDto.Tags;
            State.Options     = addJobDto.Options;
            if (addJobDto.ParentJobId.HasValue)
            {
                var parentGrain = GrainFactory.GetGrain <IJobGrain>(addJobDto.ParentJobId.Value);
                var parent      = await parentGrain.GetJobEntityAsync();

                if (parent.CurrentJobState == JobState.WaitingForActivation)
                {
                    throw new InvalidOperationException($"parent job {addJobDto.ParentJobId} not exist");
                }

                State.AncestorJobId = parent.AncestorJobId;
                await UpdateJobStateAsync(new UpdateJobStateDto(JobState.WaitingToRun), false);
            }
            else
            {
                State.AncestorJobId = jobId;
            }

            var ancestorRefGrain = GrainFactory.GetGrain <IDescendantsRefGrain>(State.AncestorJobId);
            await ancestorRefGrain.AttachToChildrenAsync(jobId);

            State.StateChanges.Add(new StateChangeDto(state));
            State.JobName = addJobDto.JobName;
            await WriteStateAsync();

            if (!State.ParentJobId.HasValue)
            {
                var indexGrain = GrainFactory.GetGrain <IShardJobIndexGrain>(Helper.GetTimeIndex());
                await indexGrain.AddToIndexAsync(new JobIndexInternal(State.JobId, State.JobName, State.CreateBy,
                                                                      State.Tags));
            }

            return(State);
        }
예제 #7
0
        public override async Task <JobEntity> CreateNewJobAsync(AddJobDto dto)
        {
            if (dto.JobId == null)
            {
                dto.JobId = await GetNextIdAsync();
            }

            var resp = await SendRequestAsync <JobEntity, AddJobDto>(HttpMethod.Post,
                                                                     "api/jobTracker/new", dto);

            if (resp.Result)
            {
                return(resp.Data);
            }

            throw new Exception($"{nameof(CreateNewJobAsync)} failed {resp.Msg}");
        }
        public async Task <JobEntityState> AddJobAsync(AddJobDto addJobDto)
        {
            if (_state.CurrentJobState != JobState.WaitingForActivation)
            {
                throw new InvalidOperationException($"job id duplicate: {this.GetPrimaryKeyLong()}");
            }

            const JobState state = JobState.WaitingToRun;
            var            jobId = this.GetPrimaryKeyLong();

            _state.JobId       = jobId;
            _state.ParentJobId = addJobDto.ParentJobId;
            _state.CreatedBy   = addJobDto.CreatedBy;
            _state.Tags        = addJobDto.Tags;
            _state.Options     = addJobDto.Options;
            if (addJobDto.ParentJobId.HasValue)
            {
                var parentGrain = GrainFactory.GetGrain <IJobGrainInMem>(addJobDto.ParentJobId.Value);
                var parent      = await parentGrain.GetJobAsync();

                if (parent.CurrentJobState == JobState.WaitingForActivation)
                {
                    throw new JobNotFoundException($"parent job {addJobDto.ParentJobId} not exist");
                }

                _state.AncestorJobId = parent.AncestorJobId;
                await UpdateJobStateAsync(new UpdateJobStateDto(JobState.WaitingToRun), false);
            }
            else
            {
                _state.AncestorJobId = jobId;
                _state.StateChanges.Add(new StateChangeDto(state));
            }

            var ancestorRefGrain = GrainFactory.GetGrain <IDescendantsRefGrainInMem>(_state.AncestorJobId);
            await ancestorRefGrain.AttachToChildrenAsync(jobId);

            _state.JobName           = addJobDto.JobName;
            _state.SourceLink        = addJobDto.SourceLink;
            _state.ActionConfigs     = addJobDto.ActionConfigs;
            _state.StateCheckConfigs = addJobDto.StateCheckConfigs;
            await ScheduleStateCheckMessageAsync(_state.StateCheckConfigs, _state.JobId);

            return(_state);
        }
예제 #9
0
        public async Task <ServiceResponse <List <GetJobDto> > > AddJob(AddJobDto newJob)
        {
            ServiceResponse <List <GetJobDto> > response = new ServiceResponse <List <GetJobDto> >();

            try
            {
                Job job = _mapper.Map <Job>(newJob);
                await _context.Jobs.AddAsync(job);

                await _context.SaveChangesAsync();

                response.Data = _context.Jobs.Select(j => _mapper.Map <GetJobDto>(j)).ToList();
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }
            return(response);
        }
예제 #10
0
        public async Task <AddJobErrorResult> AddJobFromParentAsync(AddJobDto addJobDto, long ancestorJobId,
                                                                    long?trackCountRef)
        {
            if (State.CurrentJobState != JobState.WaitingForActivation)
            {
                throw new InvalidOperationException($"job id duplicate: {this.GetPrimaryKeyLong()}");
            }

            try
            {
                const JobState state = JobState.WaitingToRun;
                State.JobId         = this.GetPrimaryKeyLong();
                State.ParentJobId   = addJobDto.ParentJobId;
                State.CreatedBy     = addJobDto.CreatedBy;
                State.Tags          = addJobDto.Tags;
                State.TrackCountRef = trackCountRef;
                State.Options       = addJobDto.Options;
                State.AncestorJobId = ancestorJobId;
                State.StateChanges.Add(new StateChangeDto(state));
                State.JobName           = addJobDto.JobName;
                State.SourceLink        = addJobDto.SourceLink;
                State.ActionConfigs     = addJobDto.ActionConfigs;
                State.StateCheckConfigs = addJobDto.StateCheckConfigs;
                await ScheduleStateCheckMessageAsync(State.StateCheckConfigs, State.JobId);
                await WriteStateAsync();
            }
            catch (Exception ex)
            {
                var res = new AddJobErrorResult {
                    JobId = this.GetPrimaryKeyLong(), Error = ex.ToString()
                };

                DeactivateOnIdle();
                return(res);
            }

            return(null);
        }
예제 #11
0
 public async Task <IActionResult> PostJob(AddJobDto newJob)
 {
     return(Ok(await _resumeService.AddJob(newJob)));
 }
예제 #12
0
        public async Task <JobEntityState> AddJobAsync(AddJobDto addJobDto)
        {
            if (State.CurrentJobState != JobState.WaitingForActivation)
            {
                throw new InvalidOperationException($"job id duplicate: {this.GetPrimaryKeyLong()}");
            }

            try
            {
                const JobState state = JobState.WaitingToRun;
                var            jobId = this.GetPrimaryKeyLong();
                State.JobId       = jobId;
                State.ParentJobId = addJobDto.ParentJobId;
                State.CreatedBy   = addJobDto.CreatedBy;
                State.Tags        = addJobDto.Tags;
                State.Options     = addJobDto.Options;
                if (addJobDto.TrackJobCount)
                {
                    State.TrackCountRef = jobId;
                }

                if (addJobDto.ParentJobId.HasValue)
                {
                    var parentGrain = GrainFactory.GetGrain <IJobGrain>(addJobDto.ParentJobId.Value);
                    var parent      = await parentGrain.GetJobAsync();

                    if (parent.CurrentJobState == JobState.WaitingForActivation)
                    {
                        throw new JobNotFoundException($"parent job {addJobDto.ParentJobId} not exist");
                    }

                    State.AncestorJobId = parent.AncestorJobId;
                    State.TrackCountRef ??= parent.TrackCountRef;
                    await UpdateJobStateAsync(new UpdateJobStateDto(JobState.WaitingToRun), false);
                }
                else
                {
                    State.AncestorJobId = jobId;
                    State.StateChanges.Add(new StateChangeDto(state));
                }

                var ancestorRefGrain = GrainFactory.GetGrain <IDescendantsRefGrain>(State.AncestorJobId);
                await ancestorRefGrain.AttachToChildrenAsync(jobId);

                State.JobName           = addJobDto.JobName;
                State.SourceLink        = addJobDto.SourceLink;
                State.ActionConfigs     = addJobDto.ActionConfigs;
                State.StateCheckConfigs = addJobDto.StateCheckConfigs;
                await ScheduleStateCheckMessageAsync(State.StateCheckConfigs, State.JobId);

                if (!State.ParentJobId.HasValue)
                {
                    var indexGrain = GrainFactory.GetGrain <IShardJobIndexGrain>(Helper.GetTimeIndex());
                    await indexGrain.AddToIndexAsync(new JobIndexInternal(State.JobId, State.JobName, State.CreatedBy,
                                                                          State.Tags));
                }

                if (State.TrackCountRef.HasValue)
                {
                    var counter = GrainFactory.GetGrain <IAggregateCounterGrain>(State.TrackCountRef.Value);
                    await counter.AddAsync();
                }
            }
            catch (Exception)
            {
                DeactivateOnIdle();
                throw;
            }

            await WriteStateAsync();

            return(State);
        }
예제 #13
0
 public async Task <ReturnDto <JobEntity> > AddNewJob(
     [FromBody] AddJobDto dto)
 {
     return(new ReturnDto <JobEntity>(await _service.AddNewJobAsync(dto)));
 }
예제 #14
0
 internal abstract Task <JobEntity> CreateNewJobWithBufferAsync(AddJobDto dto, Guid bufferId);
예제 #15
0
 public async Task <JobEntity> CreateNewJobAsync(AddJobDto dto)
 {
     return(await _client.CreateNewJobWithBufferAsync(dto, _scopeBufferId));
 }
예제 #16
0
 public abstract Task <JobEntity> CreateNewJobAsync(AddJobDto dto);
예제 #17
0
 public async Task <ReturnDto <JobEntity> > AddJobToBufferAsync([FromBody] AddJobDto dto, [FromRoute] Guid bufferId)
 {
     return(new ReturnDto <JobEntity>(await _svc.AddNewJobAsync(dto, bufferId)));
 }