Esempio n. 1
0
        private void Callback(TaskToBeWorked message)
        {
            try
            {
                _logger.LogDebug("Processing {0} for task {1}", message.StepType, message.TaskId);
                _dal.UpdateTaskStatus(message.TaskId, StatusType.Processing);

                TaskRequest request = new TaskRequest
                {
                    TaskId = message.TaskId,
                    Status = StatusType.Processing,
                    Input  = _dal.GetTaskData(message.TaskId)
                };

                TaskResponse response = ExecuteStep(message.StepId, message.StepType, request);

                if (response.Status == StatusType.Complete)
                {
                    _dal.ReleaseTask(message.TaskId, response.ReleaseValue, response.Output);
                }
                else
                {
                    _dal.UpdateTaskStatus(message.TaskId, response.Status);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Error processing task {0}", message.TaskId);
                _dal.UpdateTaskStatus(message.TaskId, StatusType.Error);
            }
        }
        public List <TaskToBeWorked> GetTasksByStatus(StatusType status)
        {
            string query = "SELECT t.ID AS TaskId, t.StepID, s.StepType FROM Task t INNER JOIN Step s ON s.ID = t.StepID WHERE t.StatusValue = @Status";

            var parameters = new Dictionary <string, object>();

            parameters.Add("@Status", (int)status);

            using (var conn = _factory.Connection)
            {
                List <TaskToBeWorked> tasks = new List <TaskToBeWorked>();

                var results = conn.ExecuteQuery(query, CommandType.Text, parameters);
                foreach (Dictionary <string, object> result in results)
                {
                    TaskToBeWorked task = new TaskToBeWorked(result);
                    tasks.Add(task);
                }

                return(tasks);
            }
        }