Exemplo n.º 1
0
        public object Execute()
        {
            logger.LogInformation("{0}: Function Started. HTTP Method: {1}, Path: {2}.", DateTime.Now.ToString(), Request.Method, Request.Path);

            Event   @event  = null;
            Context context = null;

            try
            {
                (@event, context) = parameterHandler.GetFunctionParameters(Request);
                var cancellationSource = new CancellationTokenSource();

                var output = invoker.Execute(cancellationSource, @event, context);

                logger.LogInformation("{0}: Function Executed. HTTP response: {1}.", DateTime.Now.ToString(), 200);

                LogMetrics(context, 200);
                return(output);
            }
            catch (OperationCanceledException exception)
            {
                logger.LogError(exception, "{0}: Function Cancelled. HTTP Response: {1}. Reason: {2}.", DateTime.Now.ToString(), 408, "Timeout");
                LogMetrics(context, 408);
                return(new StatusCodeResult(408));
            }
            catch (Exception exception)
            {
                logger.LogCritical(exception, "{0}: Function Corrupted. HTTP Response: {1}. Reason: {2}.", DateTime.Now.ToString(), 500, exception.Message);
                LogMetrics(context, 500);
                return(new StatusCodeResult(500));
            }
        }
Exemplo n.º 2
0
        public object Execute()
        {
            Console.WriteLine("{0}: Function Started. HTTP Method: {1}, Path: {2}.", DateTime.Now.ToString(), Request.Method, Request.Path);

            try
            {
                (Event _event, Context _context) = _parameterManager.GetFunctionParameters(Request);

                CancellationTokenSource _cancellationSource = new CancellationTokenSource();

                var output = _invoker.Execute(_function, _cancellationSource, _event, _context);

                Console.WriteLine("{0}: Function Executed. HTTP response: {1}.", DateTime.Now.ToString(), 200);
                return(output);
            }
            catch (OperationCanceledException)
            {
                Console.WriteLine("{0}: Function Cancelled. HTTP Response: {1}. Reason: {2}.", DateTime.Now.ToString(), 408, "Timeout");
                return(new StatusCodeResult(408));
            }
            catch (Exception ex)
            {
                Console.WriteLine("{0}: Function Corrupted. HTTP Response: {1}. Reason: {2}.", DateTime.Now.ToString(), 500, ex.Message);
                throw;
            }
        }
        public async Task <object> Execute()
        {
            _logger.LogInformation($"{DateTime.Now}: Function Started. HTTP Method: {Request.Method}, Path: {Request.Path}.");

            Event   @event  = null;
            Context context = null;

            try
            {
                (@event, context) = await _parameterHandler.GetFunctionParameters(Request);

                object output;
                var    durationMetrics = DurationSeconds.WithLabels(context.ModuleName, context.FunctionName, context.Runtime);
                using (durationMetrics.NewTimer()) {
                    output = await _invoker.Execute(@event, context);
                }

                _logger.LogInformation($"{DateTime.Now}: Function Executed. HTTP response: 200.");

                LogMetrics(context, 200);
                return(output);
            }
            catch (OperationCanceledException exception)
            {
                _logger.LogError(exception, $"{DateTime.Now}: Function Cancelled. HTTP Response: 408. Reason: Timeout.");
                LogMetrics(context, 408);
                return(new StatusCodeResult(408));
            }
            catch (Exception exception)
            {
                _logger.LogCritical(exception, $"{DateTime.Now}: Function Corrupted. HTTP Response: 500. Reason: {exception.Message}.");
                LogMetrics(context, 500);
                return(new StatusCodeResult(500));
            }
        }
Exemplo n.º 4
0
        public async void CheckDefaultEventFromDefaultParameterHandler(string modName, string funcHandler, string funcTimeout, string funcPort, string funcRuntime, string funcMemoryLimit)
        {
            // Arrange
            EnvironmentManager.SetVariables(modName, funcHandler, funcTimeout, funcPort, funcRuntime, funcMemoryLimit);
            IParameterHandler parameterHandler = GetDefaultParameterHandler();
            HttpRequest       httpRequest      = EnvironmentManager.GetHttpRequest();

            // Act
            (Event @event, _) = await parameterHandler.GetFunctionParameters(httpRequest);

            // Assert
            Assert.NotNull(@event);
            Assert.NotNull(@event.Extensions);
            Assert.Equal(httpRequest, @event.Extensions.HttpRequest);
            Assert.Equal(string.Empty, @event.Data);
        }
Exemplo n.º 5
0
        public async void CheckContextFromDefaultParameterHandler(string modName, string funcHandler, string funcTimeout, string funcPort, string funcRuntime, string funcMemoryLimit)
        {
            // Arrange
            EnvironmentManager.SetVariables(modName, funcHandler, funcTimeout, funcPort, funcRuntime, funcMemoryLimit);
            IParameterHandler parameterHandler = GetDefaultParameterHandler();
            HttpRequest       httpRequest      = EnvironmentManager.GetHttpRequest();

            // Act
            (_, Context context) = await parameterHandler.GetFunctionParameters(httpRequest);

            // Assert
            Assert.NotNull(context);
            Assert.Equal(modName, context.ModuleName);
            Assert.Equal(funcHandler, context.FunctionName);
            Assert.Equal(funcTimeout, context.Timeout);
            Assert.Equal(funcPort, context.FunctionPort);
            Assert.Equal(funcRuntime, context.Runtime);
            Assert.Equal(funcMemoryLimit, context.MemoryLimit);
        }
Exemplo n.º 6
0
        public async void CheckEventFromDefaultParameterHandler(string eventType, string eventNamespace)
        {
            // Arrange
            string            eventId          = Guid.NewGuid().ToString();
            string            eventTime        = DateTime.Now.ToString();
            var               data             = new { id = Guid.NewGuid() };
            IParameterHandler parameterHandler = GetDefaultParameterHandler();
            HttpRequest       httpRequest      = EnvironmentManager.GetHttpRequest(eventId, eventType, eventTime, eventNamespace, data);

            // Act
            (Event @event, _) = await parameterHandler.GetFunctionParameters(httpRequest);

            // Assert
            Assert.NotNull(@event);
            Assert.NotNull(@event.Extensions);
            Assert.Equal(httpRequest, @event.Extensions.HttpRequest);
            Assert.Equal(eventId, @event.EventId);
            Assert.Equal(eventNamespace, @event.EventNamespace);
            Assert.Equal(eventTime, @event.EventTime);
            Assert.Equal(eventType, @event.EventType);
            Assert.NotNull(@event.Data);
            Assert.Equal(data.id.ToString(), ((JsonElement)@event.Data).GetProperty("id").ToString());
        }