Пример #1
0
        /// <summary>
        /// This method is called by Azure Functions when a function has been executed. It is not intended to be called manually.
        /// </summary>
#pragma warning disable CS0618 // Type or member is obsolete
        public async Task OnExecutedAsync(FunctionExecutedContext executedContext, CancellationToken cancellationToken)
#pragma warning restore CS0618 // Type or member is obsolete
        {
            long?took = null;

            if (executedContext.Properties.ContainsKey(Constants.StopwatchKeyName))
            {
                var stopwatch = executedContext.Properties[Constants.StopwatchKeyName] as Stopwatch;
                if (stopwatch != null)
                {
                    stopwatch.Stop();
                    took = stopwatch.ElapsedMilliseconds;
                }
            }

            if (api == null)
            {
                api = (ElmahioAPI)ElmahioAPI.Create(options.ApiKey, new ElmahIoOptions
                {
                    Timeout   = options.Timeout,
                    UserAgent = UserAgent(),
                });
            }

            if (executedContext.FunctionResult.Succeeded)
            {
                await api.Heartbeats.HealthyAsync(options.LogId, options.HeartbeatId, took : took);
            }
            else
            {
                await api.Heartbeats.UnhealthyAsync(options.LogId, options.HeartbeatId, executedContext.FunctionResult.Exception?.ToString(), took : took);
            }
        }
Пример #2
0
 public async Task OnExecutedAsync(FunctionExecutedContext executedContext, CancellationToken cancellationToken)
 {
     if (_manager.IsAvailabilityTest(executedContext))
     {
         await _manager.CompleteInvocationAsync(executedContext);
     }
 }
Пример #3
0
        public Task OnExecutedAsync(FunctionExecutedContext executedContext, CancellationToken cancellationToken)
        {
            Throw.IfNull(executedContext, nameof(executedContext));

            RemoveScope(executedContext.FunctionInstanceId);
            return(Task.CompletedTask);
        }
            public Task OnExecutedAsync(FunctionExecutedContext executedContext, CancellationToken cancellationToken)
            {
                Act("Post-Instance");

                Assert.True(_field);  // set from filter.
                return(Task.CompletedTask);
            }
        public void OnExecutedAsync_WithFunctionExecutedContextAsNotNull_ReturnsCompletedTask()
        {
            // arrange
            var arguments          = new Dictionary <string, object>();
            var properties         = new Dictionary <string, object>();
            var functionInstanceId = Guid.NewGuid();
            var functionName       = "SomeName";
            var mockLogger         = new Mock <ILogger>();

            FunctionExecutedContext functionExecutedContext = new FunctionExecutedContext(
                arguments,
                properties,
                functionInstanceId,
                functionName,
                mockLogger.Object,
                new Microsoft.Azure.WebJobs.Host.Executors.FunctionResult(true));

            CancellationToken cancellationToken = new CancellationToken();

            var expected = Task.CompletedTask;

            // act
            var actual = new ScopeCleanupFilter().OnExecutedAsync(functionExecutedContext, cancellationToken);

            // assert
            Assert.Equal(expected, actual);
        }
#pragma warning disable 618
        public Task OnExecutedAsync(FunctionExecutedContext executedContext, CancellationToken cancellationToken)
#pragma warning restore 618
        {
            var instanceId = (string)executedContext.Properties[ScopeName];

            AutoFacScopes.Unregister(instanceId);
            return(Task.CompletedTask);
        }
        public void OnExecutedAsync_WithFunctionExecutedContextAsNull_ThrowsArgumentNullException()
        {
            // arrange
            FunctionExecutedContext functionExecutedContext = null;
            CancellationToken       cancellationToken       = new CancellationToken();

            // act & assert
            Assert.ThrowsAsync <ArgumentNullException>(() => new ScopeCleanupFilter().OnExecutedAsync(functionExecutedContext, cancellationToken));
        }
Пример #8
0
        public Task OnExecutedAsync(FunctionExecutedContext executedContext, CancellationToken cancellationToken)
        {
            if (executedContext == null)
            {
                throw new ArgumentNullException(nameof(executedContext));
            }

            RemoveScope(executedContext.FunctionInstanceId);
            return(Task.CompletedTask);
        }
Пример #9
0
        /// <summary>
        /// This method is called by Azure Functions when a function has been executed. It is not intended to be called manually.
        /// </summary>
#pragma warning disable CS0618 // Type or member is obsolete
        public Task OnExecutedAsync(FunctionExecutedContext executedContext, CancellationToken cancellationToken)
#pragma warning restore CS0618 // Type or member is obsolete
        {
            // Save context arguments like the HTTP context for HTTP triggered functions
            foreach (var arg in executedContext.Arguments)
            {
                executedContext.Properties.Add(arg.Key, arg.Value);
            }

            return(Task.CompletedTask);
        }
        //This may be useful later
        //public override Task OnExecutingAsync(FunctionExecutingContext executingContext, CancellationToken cancellationToken)
        //{


        //    return base.OnExecutingAsync(executingContext, cancellationToken);
        //}

        public override Task OnExecutedAsync(FunctionExecutedContext executedContext, CancellationToken cancellationToken)
        {
            System.Diagnostics.Debug.WriteLine($"[B]Function Instance ID: {executedContext.FunctionInstanceId}");
            if (_scopeDict.ContainsKey(executedContext.FunctionInstanceId))
            {
                var scope = _scopeDict[executedContext.FunctionInstanceId];
                scope.Dispose();
                _scopeDict.TryRemove(executedContext.FunctionInstanceId, out scope);
            }

            return(base.OnExecutedAsync(executedContext, cancellationToken));
        }
 static void Verify(FunctionExecutedContext context)
 {
     if (_lastError != null)
     {
         Assert.False(context.FunctionResult.Succeeded);
         Assert.Equal(_lastError, context.FunctionResult.Exception);
     }
     else
     {
         Assert.True(context.FunctionResult.Succeeded);
         Assert.Null(context.FunctionResult.Exception);
     }
 }
        public Task OnExecutedAsync(FunctionExecutedContext executedContext, CancellationToken cancellationToken)
        {
            var instanceServices = _functionInstanceServicesCatalog.GetFunctionServices(executedContext.FunctionInstanceId);

            var sqlTransactionMarker = instanceServices.GetRequiredService <SqlTransactionMarker>();

            if (sqlTransactionMarker.GotTransaction)
            {
                sqlTransactionMarker.Transaction.Commit();
                sqlTransactionMarker.OnTransactionCompleted();
            }

            return(Task.CompletedTask);
        }
            public override Task OnExecutedAsync(FunctionExecutedContext executedContext, CancellationToken cancellationToken)
            {
                Verify(executedContext);

                executedContext.Logger.LogInformation("Post_" + _id);
                Act("Post_" + _id);

                var value = executedContext.Properties["TestProperty"];

                Assert.Equal("TestValue", value);

                Assert.NotNull(executedContext.Logger);

                return(base.OnExecutedAsync(executedContext, cancellationToken));
            }
Пример #14
0
        public Task OnExecutedAsync(FunctionExecutedContext executedContext, CancellationToken cancellationToken)
        {
            var logger = executedContext.Logger;

            logger.LogInformation($"Executed {executedContext.FunctionName} with instanceId {executedContext.FunctionInstanceId}");
            foreach (var(key, value) in executedContext.Arguments)
            {
                logger.LogInformation($"Parameter {key} with value {value}");
            }
            logger.LogInformation($"Result was {(executedContext.FunctionResult.Succeeded ? " succeeded" : " failed")}");
            if (executedContext.FunctionResult.Exception != null)
            {
                logger.LogInformation(executedContext.FunctionResult.Exception.ToString());
            }
            return(Task.CompletedTask);
        }
        public override Task OnExecutedAsync(FunctionExecutedContext executedContext, CancellationToken cancellationToken)
        {
            // add to event db only if sql update succeeds
            //if (!executedContext.FunctionResult.Succeeded)
            try
            {
                var user = JsonConvert.DeserializeObject <User>(JsonConvert.SerializeObject(reqObject));

                //if (!_service.ValidateUser(user))
                //    return base.OnExecutedAsync(executedContext, cancellationToken);

                var cosmosresponse = cosmos.AppendToCosmos <dynamic>(action, moduleName, reqObject);

                return(base.OnExecutedAsync(executedContext, cancellationToken));
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
        public override Task OnExecutedAsync(FunctionExecutedContext executedContext, CancellationToken cancellationToken)
        {
            if (_state == null || !_state.IsOpen)
            {
                var request      = executedContext.Arguments.Values.FirstOrDefault(argument => argument is HttpRequest) as HttpRequest;
                var queueService = request.HttpContext.RequestServices.GetRequiredService <CircuitBreakerQueueService>();

                queueService.AddMessageAsync(new CircuitBreakerMessage
                {
                    ServiceName                         = _serviceName,
                    FailureRequestThreshold             = _failureRequestThreshold,
                    FailureRequestThresholdMilliseconds = _failureRequestThresholdMilliseconds,
                    FunctionName                        = executedContext.FunctionName,
                    HalfOpenSuccessThreshold            = _halfOpenSuccessThreshold,
                    IsSuccess = executedContext.FunctionResult.Succeeded,
                    OpenTimeoutExpireMilliseconds = _openTimeoutExpireMilliseconds,
                    LoggedTime = DateTime.Now
                }).Wait();
            }

            return(base.OnExecutedAsync(executedContext, cancellationToken));
        }
Пример #17
0
// Types 'FunctionExecutedContext' and 'IFunctionFilter' (and other Filter-related types) are marked as preview/obsolete,
// but the guidance from the Azure Functions team is to use it, so we disable the warning.
#pragma warning disable CS0618
        public Task OnExecutedAsync(FunctionExecutedContext executedContext, CancellationToken cancelControl)
#pragma warning restore CS0618
        {
            // A few lines which we need for attaching a debugger during development.
            // @ToDo: Remove before shipping.
            Console.WriteLine($"Filter Entry Point: {nameof(FunctionInvocationManagementFilter)}.{nameof(OnExecutedAsync)}(..).");
            Console.WriteLine($"FunctionInstanceId: {Format.SpellIfNull(executedContext?.FunctionInstanceId)}.");
            Process proc = Process.GetCurrentProcess();

            Console.WriteLine($"Process name: \"{proc.ProcessName}\", Process Id: \"{proc.Id}\".");
            // --

            Exception error = null;

            if (executedContext?.FunctionResult?.Succeeded != true)
            {
                error = executedContext?.FunctionResult?.Exception;
                error = error ?? new Exception("FunctionResult.Succeeded is false, but no Exception information is available.");
            }

            OnPostFunctionError(executedContext, error, nameof(OnExecutedAsync));

            return(Task.CompletedTask);
        }
 /// <summary>
 /// Post-execution filter.
 /// </summary>
 /// <param name="executedContext">The executedContext<see cref="FunctionExecutedContext"/>.</param>
 /// <param name="cancellationToken">The cancellationToken<see cref="CancellationToken"/>.</param>
 /// <returns>The <see cref="Task"/>.</returns>
 public Task OnExecutedAsync(FunctionExecutedContext executedContext, CancellationToken cancellationToken)
 {
     // Nothing.
     return(Task.CompletedTask);
 }
Пример #19
0
 public Task OnExecutedAsync(FunctionExecutedContext executedContext, CancellationToken cancellationToken)
 {
     executedContext.Logger.LogInformation($"Executing {nameof(OnExecutedAsync)} in filter {nameof(LogFilter)}");
     return(Task.CompletedTask);
 }
Пример #20
0
 public Task OnExecutedAsync(FunctionExecutedContext executedContext, CancellationToken cancellationToken)
 {
     logger.LogDebug($"I should be executed at last");
     return(Task.CompletedTask);
 }
#pragma warning disable CS0618 // Type or member is obsolete: in preview
        public Task OnExecutedAsync(FunctionExecutedContext executedContext, CancellationToken cancellationToken)
#pragma warning restore CS0618 // Type or member is obsolete
        {
            return(Task.CompletedTask);
        }
 public Task OnExecutedAsync(FunctionExecutedContext executedContext, CancellationToken cancellationToken)
 {
     Verify(executedContext);
     Act("Post-Instance");
     return(Task.CompletedTask);
 }
Пример #23
0
 public Task OnExecutedAsync(FunctionExecutedContext executedContext, CancellationToken cancellationToken)
 {
     return(_documentSession.SaveChangesAsync(cancellationToken));
 }
 public override Task OnExecutedAsync(FunctionExecutedContext executedContext, CancellationToken cancellationToken)
 {
     return(base.OnExecutedAsync(executedContext, cancellationToken));
 }
 public Task OnExecutedAsync(FunctionExecutedContext executedContext, CancellationToken cancellationToken)
 {
     RemoveScope(executedContext.FunctionInstanceId);
     return(Task.CompletedTask);
 }
 public override Task OnExecutedAsync(FunctionExecutedContext executedContext, CancellationToken cancellationToken)
 {
     Append(executedContext, "[Post-M1]");
     Assert.Equal(ArgValue, executedContext.Arguments["myarg"]);
     return(Task.CompletedTask);
 }