public async Task <IActionResult> Next([FromQuery] string agentId)
        {
            try
            {
                if (agentId == null)
                {
                    ModelState.AddModelError("Next", "No Agent ID was passed");
                    return(BadRequest(ModelState));
                }

                bool isValid = Guid.TryParse(agentId, out Guid agentGuid);
                if (!isValid)
                {
                    ModelState.AddModelError("Next", "Agent ID is not a valid GUID ");
                    return(BadRequest(ModelState));
                }

                JsonPatchDocument <Job> statusPatch = new JsonPatchDocument <Job>();
                statusPatch.Replace(j => j.JobStatus, JobStatusType.Assigned);
                statusPatch.Replace(j => j.DequeueTime, DateTime.UtcNow);

                NextJobViewModel nextJob = jobManager.GetNextJob(agentGuid);

                return(Ok(nextJob));
            }
            catch (Exception ex)
            {
                return(ex.GetActionResult());
            }
        }
        /// <summary>
        /// Gets the oldest available job for the specified Agent id
        /// </summary>
        /// <param name="agentId"></param>
        /// <returns>Next available Job if one exists</returns>
        public NextJobViewModel GetNextJob(string agentId)
        {
            if (agentId == null)
            {
                throw new EntityOperationException("No Agent ID was passed");
            }

            bool isValid = Guid.TryParse(agentId, out Guid agentGuid);

            if (!isValid)
            {
                throw new EntityOperationException("Agent ID is not a valid GUID");
            }

            //get all new jobs of the agent group and assign the oldest one to the current agent
            var job = GetAgentGroupJob(agentGuid);

            var jobParameters = _jobManager.GetJobParameters(job?.Id ?? Guid.Empty);

            NextJobViewModel nextJob = new NextJobViewModel()
            {
                IsJobAvailable = job == null ? false : true,
                AssignedJob    = job,
                JobParameters  = jobParameters
            };

            return(nextJob);
        }
Example #3
0
        //Gets the next available job for the given agentId
        public NextJobViewModel GetNextJob(Guid agentId)
        {
            Job job = repo.Find(0, 1).Items
                      .Where(j => j.AgentId == agentId && j.JobStatus == JobStatusType.New)
                      .OrderBy(j => j.CreatedOn)
                      .FirstOrDefault();

            NextJobViewModel nextJob = new NextJobViewModel()
            {
                IsJobAvailable = job == null ? false : true,
                AssignedJob    = job
            };

            return(nextJob);
        }