public async Task <IResultModel> Add(JobAddModel model) { var entity = _mapper.Map <JobEntity>(model); entity.JobKey = $"{model.Group}.{model.Code}"; entity.Status = JobStatus.Stop; entity.EndDate = entity.EndDate.AddDays(1); entity.JobType = JobType.Normal; if (await _repository.Exists(entity)) { return(ResultModel.Failed($"当前任务组{entity.Group}已存在任务编码${entity.Code}")); } //是否立即启动 if (model.Start) { var result = await AddJob(entity); if (!result.Successful) { return(result); } entity.Status = JobStatus.Running; } return(ResultModel.Result(await _repository.AddAsync(entity))); }
public async Task <ActionResult> ScheduleTwinUpdate(ScheduleTwinUpdateModel model) { var twin = new Twin(); foreach (var tagModel in model.Tags.Where(m => !string.IsNullOrWhiteSpace(m.TagName))) { string key = tagModel.TagName; if (tagModel.isDeleted) { twin.Set(key, null); } else { TwinExtension.Set(twin, key, getDyanmicValue(tagModel.DataType, tagModel.TagValue)); } await _nameCacheLogic.AddNameAsync(tagModel.TagName); } foreach (var propertyModel in model.DesiredProperties.Where(m => !string.IsNullOrWhiteSpace(m.PropertyName))) { string key = propertyModel.PropertyName; if (propertyModel.isDeleted) { twin.Set(key, null); } else { TwinExtension.Set(twin, key, getDyanmicValue(propertyModel.DataType, propertyModel.PropertyValue)); } await _nameCacheLogic.AddNameAsync(propertyModel.PropertyName); } twin.ETag = "*"; var deviceListFilter = await GetFilterById(model.FilterId); string queryCondition = deviceListFilter.GetSQLCondition(); // The query condition can not be empty when schduling job, use a default clause // is_defined(deviceId) to represent no clause condition for all devices. var jobId = await _iotHubDeviceManager.ScheduleTwinUpdate( string.IsNullOrWhiteSpace(queryCondition)? "is_defined(deviceId)" : queryCondition, twin, model.StartDateUtc, (int)(model.MaxExecutionTimeInMinutes * 60)); await _jobRepository.AddAsync(new JobRepositoryModel(jobId, model.FilterId, model.JobName, deviceListFilter.Name, ExtendJobType.ScheduleUpdateTwin, null)); return(RedirectToAction("Index", "Job", new { jobId = jobId })); }
public async Task <IResultModel> Add(JobAddModel model) { var entity = _mapper.Map <JobEntity>(model); entity.JobKey = $"{model.Group}.{model.Code}"; entity.Status = JobStatus.Pause;//默认添加后暂停,需要手动启动 entity.EndDate = entity.EndDate.AddDays(1); if (await _repository.Exists(entity)) { return(ResultModel.Failed($"当前任务组{entity.Group}已存在任务编码${entity.Code}")); } using (var tran = _repository.BeginTransaction()) { if (await _repository.AddAsync(entity, tran)) { var result = await AddJob(entity); if (!result.Successful) { return(result); } tran.Commit(); return(ResultModel.Success()); } } return(ResultModel.Failed("添加失败")); }
public async Task <IResultModel> Add(JobAddModel model) { var entity = _mapper.Map <JobEntity>(model); entity.JobKey = $"{model.Group}.{model.Code}"; entity.Status = JobStatus.Pause;//Ĭ�����Ӻ���ͣ����Ҫ�ֶ����� entity.EndDate = entity.EndDate.AddDays(1); if (await _repository.Exists(entity)) { return(ResultModel.Failed($"��ǰ������{entity.Group}�Ѵ����������${entity.Code}")); } using (var uow = _dbContext.NewUnitOfWork()) { if (await _repository.AddAsync(entity, uow)) { var result = await AddJob(entity); if (!result.Successful) { return(result); } uow.Commit(); return(ResultModel.Success()); } } return(ResultModel.Failed("����ʧ��")); }
/// <summary> /// Allows a user to update IP Details in batches. /// </summary> /// <param name="ipDetails">An array of IP detail objects, including their IP that will be updated.</param> /// <returns>The unique identifier of the particular BatchUpdate.</returns> public Guid BatchUpdateDetails(IPDetailsToUpdateDTO[] ipDetails) { JsonSerializerOptions options = new JsonSerializerOptions() { PropertyNameCaseInsensitive = true }; string requestJSON = JsonSerializer.Serialize(ipDetails, options); JobModel jobModel = new JobModel() { BatchOperationResult = Kernel.Enums.Result.InProcess, ItemsDone = 0, ItemsLeft = ipDetails.Count(), ItemsSucceeded = 0, JobKey = Guid.NewGuid(), requestJSON = requestJSON }; Guid jobKey = _repository.AddAsync(jobModel).GetAwaiter().GetResult().JobKey; Task.Factory.StartNew(() => _batchTaskRunner.ProcessBatchJob(jobKey), new CancellationToken()); return(jobKey); }
public async Task <IResultModel> Add(JobAddModel model) { var entity = _mapper.Map <JobEntity>(model); //if (await _repository.Exists(entity)) //{ //return ResultModel.HasExists; //} var result = await _repository.AddAsync(entity); return(ResultModel.Result(result)); }
public async Task <UseCaseResult <JobModel> > Handle(RequestQuote request, CancellationToken cancellationToken) { try { // fetch user id var user = await _userService.GetUserByEmailAsync(request.Email); if (user == null) { user = new OvertureUser { Name = request.Name, AccountType = AccountType.Personal, Email = request.Email, }; user = await _userService.CreateUserAsync(user, "TODO:ChangeThisToARandomPassword"); } return(new UseCaseResult <JobModel> { ResultCode = "Ok", ResultText = "Create Job", Data = _mapper.Map <JobModel>(await _jobRepository.AddAsync(new Job { UserId = user.UserId, Title = request.Title, Description = request.Description, RequiredDate = request.RequiredDate, Quotes = new List <Quote>() { new Quote() { QuotedByBusinessId = request.BusinessId } } })) }); } catch (Exception e) { return(new UseCaseResult <JobModel> { ResultCode = "Error", ResultText = e.Message, Data = null }); }; }
public async Task <CreateJobCommandResponse> Handle( CreateJobCommand request, CancellationToken cancellationToken) { var createJobCommandResponse = new CreateJobCommandResponse(); // validations goes here! var uniqueJob = await jobRepository.GetJobByEverjobAsync(request.EverJob); if (uniqueJob != null) { throw new Exception($"Já existe uma vaga cadastrada com o código Everjob {request.EverJob}"); } // ====================== var job = new Job() { EverJob = request.EverJob, LeaderCenters = request.LeaderCenters, LtfOrPl = request.LtfOrPl, ManagerSp = request.ManagerSp, Community = request.Community, Squad = request.Squad, ProjectId = request.ProjectId, AllocationTypeId = request.AllocationTypeId, OpeningDate = request.OpeningDate, Technology = request.Technology, YearsOfExperience = request.YearsOfExperience, DesiredDate = request.DesiredDate, MaximumSalary = request.MaximumSalary, Recruiter = request.Recruiter, Priority = request.Priority, PriorityDate = request.PriorityDate, StatusJobId = request.StatusJobId, Justification = request.Justification }; job = await jobRepository.AddAsync(job); createJobCommandResponse.Job = mapper.Map <CreateJobDto>(job); return(createJobCommandResponse); }
public async Task <string> ExclusiveCreateAsync(string name, IContextParameters @params) { var userId = _userResolver.GetUserId(); if (string.IsNullOrEmpty(userId)) { throw new ArgumentNullException(nameof(userId)); } if (await _lockService.LockAsync(name) == false) { await _lockService.UnlockAsync(name); //return null; } var job = await _jobRepository.AddAsync(new Job(name, userId, @params)); _jobRegistory.AddJob(job); _jobRegistory.Enqueue(job.Id); return(job.Id); }
public async Task <long?> ExclusiveCreateAsync <TParams>(string name, TParams @params) { var userId = _userResolver.GetUserId(); if (string.IsNullOrEmpty(userId)) { throw new ArgumentNullException(nameof(userId)); } if (await _lockService.LockAsync(name) == false) { return(null); } var job = new Job(name, userId, @params); job.Id = await _jobRepository.AddAsync(job); _jobRegistory.AddJob(job.Id, job); _jobRegistory.Enqueue(job.Id); return(job.Id); }
public async Task <Job> CreateJobAsync(Job job) { var addedJob = await _jobRepository.AddAsync(job); return(addedJob); }
async Task AddJobs(IJobRepository repo) { await repo.AddAsync(new Job { Name = "Test1" }); await repo.AddAsync(new Job { Name = "Test1" }); await repo.AddAsync(new Job { Name = "Test1" }); await repo.AddAsync(new Job { Name = "Test1" }); await repo.AddAsync(new Job { Name = "Test1" }); await repo.AddAsync(new Job { Name = "Test1" }); await repo.AddAsync(new Job { Name = "Test2" }); await repo.AddAsync(new Job { Name = "Test2" }); await repo.AddAsync(new Job { Name = "Test2" }); await repo.AddAsync(new Job { Name = "Test2" }); await repo.AddAsync(new Job { Name = "Test3" }); await repo.AddAsync(new Job { Name = "Test3" }); }