/// <summary> /// Takes an AgentGroup and returns it for addition /// </summary> /// <param name="agentGroup"></param> /// <returns>The AgentGroup to be added</returns> public AgentGroup AddAgentGroup(AgentGroup agentGroup) { var namedAgentGroup = _agentGroupRepository.Find(null, d => d.Name.ToLower() == agentGroup.Name.ToLower())?.Items?.FirstOrDefault(); if (namedAgentGroup != null) { throw new EntityAlreadyExistsException("Agent group name already exists"); } return(agentGroup); }
public Job GetAgentGroupJob(Guid agentGuid) { List <Job> agentGroupJobs = new List <Job>(); var agentGroupsMembers = GetAllMembersInGroup(agentGuid.ToString()).Items; foreach (var member in agentGroupsMembers) { AgentGroup agentGroup = _agentGroupRepository.Find(null, g => g.Id == member.AgentGroupId).Items?.FirstOrDefault(); //if agent group is disabled, then do not retreive jobs from that group if (agentGroup.IsEnabled == false) { continue; } var memberGroupJobs = _jobRepo.Find(null, j => j.AgentGroupId == member.AgentGroupId && j.JobStatus == JobStatusType.New).Items; agentGroupJobs = agentGroupJobs.Concat(memberGroupJobs).ToList(); } var agentJobs = _jobRepo.Find(null, j => j.AgentId == agentGuid && j.JobStatus == JobStatusType.New).Items; var allAgentJobs = agentGroupJobs.Concat(agentJobs).ToList(); Job job = allAgentJobs.OrderBy(j => j.CreatedOn).FirstOrDefault(); //update job if (job != null) { job.JobStatus = JobStatusType.Assigned; job.DequeueTime = DateTime.UtcNow; job.AgentId = agentGuid; try { job = _jobRepo.Update(job); } catch (EntityConcurrencyException ex) { job = null; } } return(job); }