Exemplo n.º 1
0
        public async Task <IActionResult> RunNow([FromBody] RunNowViewModel request)
        {
            try
            {
                Guid AutomationID = request.AutomationId;
                Guid AgentID      = request.AgentId;

                Schedule schedule = new Schedule();
                schedule.AgentId        = AgentID;
                schedule.CRONExpression = "";
                schedule.LastExecution  = DateTime.UtcNow;
                schedule.NextExecution  = DateTime.UtcNow;
                schedule.IsDisabled     = false;
                schedule.ProjectId      = null;
                schedule.StartingType   = "RunNow";
                schedule.Status         = "New";
                schedule.ExpiryDate     = DateTime.UtcNow.AddDays(1);
                schedule.StartDate      = DateTime.UtcNow;
                schedule.AutomationId   = AutomationID;
                schedule.CreatedOn      = DateTime.UtcNow;
                schedule.CreatedBy      = applicationUser?.UserName;

                var jsonScheduleObj = JsonSerializer.Serialize <Schedule>(schedule);
                var jobId           = BackgroundJob.Enqueue(() => hubManager.ExecuteJob(jsonScheduleObj, request.JobParameters));

                return(Ok());
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("RunNow", ex.Message);
                return(BadRequest(ModelState));
            }
        }
        public async Task <IActionResult> RunNow([FromBody] RunNowViewModel request)
        {
            try
            {
                ParametersViewModel.VerifyParameterNameAvailability(request.JobParameters);

                Guid AutomationId = request.AutomationId;
                Guid AgentId      = request.AgentId;
                Guid AgentGroupId = request.AgentGroupId;

                Schedule schedule = new Schedule();
                schedule.AgentId        = AgentId;
                schedule.AgentGroupId   = AgentGroupId;
                schedule.CRONExpression = "";
                schedule.LastExecution  = DateTime.UtcNow;
                schedule.NextExecution  = DateTime.UtcNow;
                schedule.IsDisabled     = false;
                schedule.ProjectId      = null;
                schedule.StartingType   = "RunNow";
                schedule.Status         = "New";
                schedule.ExpiryDate     = DateTime.UtcNow.AddDays(1);
                schedule.StartDate      = DateTime.UtcNow;
                schedule.AutomationId   = AutomationId;
                schedule.CreatedOn      = DateTime.UtcNow;
                schedule.CreatedBy      = applicationUser?.UserName;

                var jsonScheduleObj = JsonSerializer.Serialize <Schedule>(schedule);
                _hubManager.ExecuteJob(jsonScheduleObj, request.JobParameters);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(ex.GetActionResult());
            }
        }