예제 #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));
            }
        }
예제 #2
0
        public QueueItem Enqueue(QueueItem item)
        {
            item.State        = QueueItemStateType.New.ToString();
            item.StateMessage = "Successfully created new queue item.";
            item.IsLocked     = false;
            if (item.Priority == 0)
            {
                item.Priority = 100;
            }

            //check if a queue arrival schedule exists for this queue
            Schedule existingSchedule = _scheduleRepo.Find(0, 1).Items?.Where(s => s.QueueId == item.QueueId)?.FirstOrDefault();

            if (existingSchedule != null && existingSchedule.IsDisabled == false && existingSchedule.StartingType.ToLower().Equals("queuearrival"))
            {
                Schedule schedule = new Schedule();
                schedule.AgentId        = existingSchedule.AgentId;
                schedule.CRONExpression = "";
                schedule.LastExecution  = DateTime.UtcNow;
                schedule.NextExecution  = DateTime.UtcNow;
                schedule.IsDisabled     = false;
                schedule.ProjectId      = null;
                schedule.StartingType   = "QueueArrival";
                schedule.Status         = "New";
                schedule.ExpiryDate     = DateTime.UtcNow.AddDays(1);
                schedule.StartDate      = DateTime.UtcNow;
                schedule.AutomationId   = existingSchedule.AutomationId;

                var jsonScheduleObj = System.Text.Json.JsonSerializer.Serialize(schedule);
                //call GetScheduleParameters()
                var jobId = BackgroundJob.Enqueue(() => _hubManager.ExecuteJob(jsonScheduleObj, Enumerable.Empty <ParametersViewModel>()));
            }

            QueueItem queueItem = new QueueItem()
            {
                CreatedBy          = _httpContextAccessor.HttpContext.User.Identity.Name,
                CreatedOn          = DateTime.UtcNow,
                DataJson           = item.DataJson,
                Event              = item.Event,
                ExpireOnUTC        = item.ExpireOnUTC,
                IsLocked           = item.IsLocked,
                JsonType           = item.JsonType,
                Name               = item.Name,
                PostponeUntilUTC   = item.PostponeUntilUTC,
                Priority           = item.Priority,
                QueueId            = item.QueueId,
                RetryCount         = item.RetryCount,
                Source             = item.Source,
                State              = item.State,
                StateMessage       = item.StateMessage,
                Type               = item.Type,
                PayloadSizeInBytes = 0
            };

            return(item);
        }
        public QueueItem Enqueue(QueueItem item)
        {
            item.State = QueueItemStateType.New.ToString();
            item.PayloadSizeInBytes = 0;
            item.StateMessage       = "Successfully created new queue item.";
            item.IsLocked           = false;
            if (item.Priority == 0)
            {
                item.Priority = 100;
            }

            //check if a queue arrival schedule exists for this queue
            var existingSchedules = _scheduleRepo.Find(null, s => s.QueueId == item.QueueId)?.Items;

            foreach (Schedule existingSchedule in existingSchedules)
            {
                if (existingSchedule != null && existingSchedule.IsDisabled == false && existingSchedule.StartingType.ToLower().Equals("queuearrival"))
                {
                    Schedule schedule = new Schedule();
                    schedule.Id             = existingSchedule.Id;
                    schedule.AgentId        = existingSchedule.AgentId;
                    schedule.CRONExpression = "";
                    schedule.LastExecution  = DateTime.UtcNow;
                    schedule.NextExecution  = DateTime.UtcNow;
                    schedule.IsDisabled     = false;
                    schedule.ProjectId      = null;
                    schedule.StartingType   = "QueueArrival";
                    schedule.Status         = "New";
                    schedule.ExpiryDate     = DateTime.UtcNow.AddDays(1);
                    schedule.StartDate      = DateTime.UtcNow;
                    schedule.AutomationId   = existingSchedule.AutomationId;
                    schedule.MaxRunningJobs = existingSchedule.MaxRunningJobs;

                    var jsonScheduleObj = System.Text.Json.JsonSerializer.Serialize(schedule);
                    //call GetScheduleParameters()
                    var jobId = BackgroundJob.Enqueue(() => _hubManager.ExecuteJob(jsonScheduleObj, Enumerable.Empty <ParametersViewModel>()));
                }
            }
            UpdateItemsStates(item.QueueId.ToString());

            return(item);
        }
        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());
            }
        }
예제 #5
0
        public async Task <IActionResult> Enqueue([FromBody] QueueItem request)
        {
            try
            {
                if (organizationSettingManager.HasDisallowedExecution())
                {
                    return(StatusCode(StatusCodes.Status405MethodNotAllowed, "Organization is set to DisallowExecution"));
                }

                var response = await manager.Enqueue(request);

                //check if a queue arrival schedule exists for this queue
                Schedule existingSchedule = scheduleRepo.Find(0, 1).Items?.Where(s => s.QueueId == response.QueueId)?.FirstOrDefault();
                if (existingSchedule != null && existingSchedule.IsDisabled == false && existingSchedule.StartingType.ToLower().Equals("queuearrival"))
                {
                    Schedule schedule = new Schedule();
                    schedule.AgentId        = existingSchedule.AgentId;
                    schedule.CRONExpression = "";
                    schedule.LastExecution  = DateTime.UtcNow;
                    schedule.NextExecution  = DateTime.UtcNow;
                    schedule.IsDisabled     = false;
                    schedule.ProjectId      = null;
                    schedule.StartingType   = "QueueArrival";
                    schedule.Status         = "New";
                    schedule.ExpiryDate     = DateTime.UtcNow.AddDays(1);
                    schedule.StartDate      = DateTime.UtcNow;
                    schedule.AutomationId   = existingSchedule.AutomationId;

                    var jsonScheduleObj = System.Text.Json.JsonSerializer.Serialize(schedule);
                    //call GetScheduleParameters()
                    var jobId = BackgroundJob.Enqueue(() => hubManager.ExecuteJob(jsonScheduleObj, Enumerable.Empty <ParametersViewModel>()));
                }

                QueueItem queueItem = new QueueItem()
                {
                    CreatedBy          = applicationUser.Name,
                    CreatedOn          = DateTime.UtcNow,
                    DataJson           = response.DataJson,
                    Event              = response.Event,
                    ExpireOnUTC        = response.ExpireOnUTC,
                    IsLocked           = response.IsLocked,
                    JsonType           = response.JsonType,
                    Name               = response.Name,
                    PostponeUntilUTC   = response.PostponeUntilUTC,
                    Priority           = response.Priority,
                    QueueId            = response.QueueId,
                    RetryCount         = response.RetryCount,
                    Source             = response.Source,
                    State              = response.State,
                    StateMessage       = response.StateMessage,
                    Type               = response.Type,
                    PayloadSizeInBytes = 0
                };

                //create queue item
                IActionResult actionResult = await base.PostEntity(queueItem);

                await webhookPublisher.PublishAsync("QueueItems.NewQueueItemCreated", response.Id.ToString(), response.Name).ConfigureAwait(false);

                //send SignalR notification to all connected clients
                await _hub.Clients.All.SendAsync("sendnotification", "New queue item added.");

                QueueItemViewModel queueItemViewModel = new QueueItemViewModel();
                queueItemViewModel = queueItemViewModel.Map(queueItem);
                string id = response.Id.ToString();
                queueItemViewModel = manager.GetQueueItemView(queueItemViewModel, id);

                return(Ok(queueItemViewModel));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("Enqueue", ex.Message);
                return(BadRequest(ModelState));
            }
        }