public FunctionExecutor(IFunctionInstanceLogger functionInstanceLogger, IFunctionOutputLogger functionOutputLogger,
                                IBackgroundExceptionDispatcher backgroundExceptionDispatcher, TraceWriter trace, TimeSpan?functionTimeout)
        {
            if (functionInstanceLogger == null)
            {
                throw new ArgumentNullException("functionInstanceLogger");
            }

            if (functionOutputLogger == null)
            {
                throw new ArgumentNullException("functionOutputLogger");
            }

            if (backgroundExceptionDispatcher == null)
            {
                throw new ArgumentNullException("backgroundExceptionDispatcher");
            }

            if (trace == null)
            {
                throw new ArgumentNullException("trace");
            }

            _functionInstanceLogger        = functionInstanceLogger;
            _functionOutputLogger          = functionOutputLogger;
            _backgroundExceptionDispatcher = backgroundExceptionDispatcher;
            _trace           = trace;
            _functionTimeout = functionTimeout;
        }
        public FunctionExecutor(IFunctionInstanceLogger functionInstanceLogger, IFunctionOutputLogger functionOutputLogger,
                                IWebJobsExceptionHandler exceptionHandler, TraceWriter trace, IAsyncCollector <FunctionInstanceLogEntry> functionEventCollector = null,
                                ILoggerFactory loggerFactory = null)
        {
            if (functionInstanceLogger == null)
            {
                throw new ArgumentNullException("functionInstanceLogger");
            }

            if (functionOutputLogger == null)
            {
                throw new ArgumentNullException("functionOutputLogger");
            }

            if (exceptionHandler == null)
            {
                throw new ArgumentNullException("exceptionHandler");
            }

            if (trace == null)
            {
                throw new ArgumentNullException("trace");
            }

            _functionInstanceLogger = functionInstanceLogger;
            _functionOutputLogger   = functionOutputLogger;
            _exceptionHandler       = exceptionHandler;
            _trace = trace;
            _functionEventCollector = functionEventCollector;
            _logger        = loggerFactory?.CreateLogger(LogCategories.Executor);
            _resultsLogger = loggerFactory?.CreateLogger(LogCategories.Results);
        }
 private static IServiceProvider CreateServiceProvider <TResult>(IStorageAccount storageAccount, Type programType,
                                                                 IExtensionTypeLocator extensionTypeLocator, TaskCompletionSource <TResult> taskSource,
                                                                 IFunctionInstanceLogger functionInstanceLogger, IExtensionRegistry extensions = null)
 {
     return(CreateServiceProvider <TResult>(storageAccount, programType, extensionTypeLocator,
                                            DefaultJobActivator.Instance, taskSource, functionInstanceLogger, extensions));
 }
        private void EnsureLoggers()
        {
            if (_loggersSet)
            {
                return;
            }

            IFunctionInstanceLogger functionLogger = new FunctionInstanceLogger(_loggerFactory);


            if (_storageAccountOptions.Dashboard != null)
            {
                var dashboardAccount = _storageAccountOptions.GetDashboardStorageAccount();

                // Create logging against a live Azure account.
                var dashboardBlobClient = dashboardAccount.CreateCloudBlobClient();
                IPersistentQueueWriter <PersistentQueueMessage> queueWriter = new PersistentQueueWriter <PersistentQueueMessage>(dashboardBlobClient);
                PersistentQueueLogger queueLogger = new PersistentQueueLogger(queueWriter);
                _hostInstanceLogger     = queueLogger;
                _functionInstanceLogger = new CompositeFunctionInstanceLogger(queueLogger, functionLogger);
                _functionOutputLogger   = new BlobFunctionOutputLogger(dashboardBlobClient);
            }
            else
            {
                // No auxillary logging. Logging interfaces are nops or in-memory.
                _hostInstanceLogger     = new NullHostInstanceLogger();
                _functionInstanceLogger = functionLogger;
                _functionOutputLogger   = new NullFunctionOutputLogger();
            }

            _loggersSet = true;
        }
 public HostMessageExecutor(IFunctionExecutor innerExecutor, IFunctionIndexLookup functionLookup,
                            IFunctionInstanceLogger functionInstanceLogger)
 {
     _innerExecutor          = innerExecutor;
     _functionLookup         = functionLookup;
     _functionInstanceLogger = functionInstanceLogger;
 }
        private async Task EnsureLoggersAsync(CancellationToken cancellationToken)
        {
            if (_loggersSet)
            {
                return;
            }

            IStorageAccount dashboardAccount = await _storageAccountProvider.GetDashboardAccountAsync(cancellationToken);
            IFunctionInstanceLogger traceWriterFunctionLogger = new TraceWriterFunctionInstanceLogger(_trace);

            if (dashboardAccount != null)
            {
                // Create logging against a live Azure account.
                IStorageBlobClient dashboardBlobClient = dashboardAccount.CreateBlobClient();
                IPersistentQueueWriter<PersistentQueueMessage> queueWriter = new PersistentQueueWriter<PersistentQueueMessage>(dashboardBlobClient);
                PersistentQueueLogger queueLogger = new PersistentQueueLogger(queueWriter);
                _hostInstanceLogger = queueLogger;
                _functionInstanceLogger = new CompositeFunctionInstanceLogger(queueLogger, traceWriterFunctionLogger);
                _functionOutputLogger = new BlobFunctionOutputLogger(dashboardBlobClient);
            }
            else
            {
                // No auxillary logging. Logging interfaces are nops or in-memory.
                _hostInstanceLogger = new NullHostInstanceLogger();
                _functionInstanceLogger = traceWriterFunctionLogger;
                _functionOutputLogger = new ConsoleFunctionOutputLogger();
            }

            _loggersSet = true;
        }
        public FunctionExecutor(IFunctionInstanceLogger functionInstanceLogger, IFunctionOutputLogger functionOutputLogger,
                                IWebJobsExceptionHandler exceptionHandler, TraceWriter trace, IAsyncCollector <FunctionInstanceLogEntry> fastLogger = null)
        {
            if (functionInstanceLogger == null)
            {
                throw new ArgumentNullException("functionInstanceLogger");
            }

            if (functionOutputLogger == null)
            {
                throw new ArgumentNullException("functionOutputLogger");
            }

            if (exceptionHandler == null)
            {
                throw new ArgumentNullException("exceptionHandler");
            }

            if (trace == null)
            {
                throw new ArgumentNullException("trace");
            }

            _functionInstanceLogger = functionInstanceLogger;
            _functionOutputLogger   = functionOutputLogger;
            _exceptionHandler       = exceptionHandler;
            _trace      = trace;
            _fastLogger = fastLogger;
        }
Example #8
0
        private async Task EnsureLoggersAsync(CancellationToken cancellationToken)
        {
            if (_loggersSet)
            {
                return;
            }

            IStorageAccount dashboardAccount =
                await _storageAccountProvider.GetDashboardAccountAsync(cancellationToken);

            if (dashboardAccount != null)
            {
                // Create logging against a live Azure account.
                IStorageBlobClient dashboardBlobClient = dashboardAccount.CreateBlobClient();
                IPersistentQueueWriter <PersistentQueueMessage> queueWriter =
                    new PersistentQueueWriter <PersistentQueueMessage>(dashboardBlobClient);
                PersistentQueueLogger queueLogger = new PersistentQueueLogger(queueWriter);
                _hostInstanceLogger     = queueLogger;
                _functionInstanceLogger = new CompositeFunctionInstanceLogger(queueLogger,
                                                                              new ConsoleFunctionInstanceLogger());
                _functionOutputLogger = new BlobFunctionOutputLogger(dashboardBlobClient);
            }
            else
            {
                // No auxillary logging. Logging interfaces are nops or in-memory.
                _hostInstanceLogger     = new NullHostInstanceLogger();
                _functionInstanceLogger = new ConsoleFunctionInstanceLogger();
                _functionOutputLogger   = new ConsoleFunctionOutputLogger();
            }

            _loggersSet = true;
        }
Example #9
0
        private static IHost CreateConfiguration <TResult>(StorageAccount storageAccount, Type programType,
                                                           IJobActivator activator, TaskCompletionSource <TResult> taskSource,
                                                           IFunctionInstanceLogger functionInstanceLogger, IExtensionRegistry extensions = null)
        {
            StorageAccountProvider storageAccountProvider = null; //  new FakeStorageAccountProvider(storageAccount); $$$

            IWebJobsExceptionHandler exceptionHandler = new TaskBackgroundExceptionHandler <TResult>(taskSource);

            return(new HostBuilder()
                   .ConfigureDefaultTestHost(b =>
            {
                b.UseHostId(Guid.NewGuid().ToString("N"))
                .AddAzureStorage();
            }, programType)
                   .ConfigureServices(services =>
            {
                // services.AddSingleton<IOptionsFactory<JobHostQueuesOptions>, FakeQueuesOptionsFactory>(); $$$ ???

                services.AddSingletonIfNotNull(storageAccountProvider);
                services.AddSingletonIfNotNull(activator);
                services.AddSingletonIfNotNull(exceptionHandler);
                services.AddSingletonIfNotNull(extensions);

                services.AddSingleton <IFunctionInstanceLoggerProvider>(new NullFunctionInstanceLoggerProvider(functionInstanceLogger));
                services.AddSingleton <IHostInstanceLoggerProvider>(new NullHostInstanceLoggerProvider());
                services.AddSingleton <IFunctionOutputLoggerProvider>(new NullFunctionOutputLoggerProvider());
            })
                   .Build());
        }
        public HostMessageListenerFactory(IStorageQueue queue,
                                          IQueueConfiguration queueConfiguration,
                                          IWebJobsExceptionHandler exceptionHandler,
                                          TraceWriter trace,
                                          ILoggerFactory loggerFactory,
                                          IFunctionIndexLookup functionLookup,
                                          IFunctionInstanceLogger functionInstanceLogger,
                                          IFunctionExecutor executor)
        {
            if (queue == null)
            {
                throw new ArgumentNullException("queue");
            }

            if (queueConfiguration == null)
            {
                throw new ArgumentNullException("queueConfiguration");
            }

            if (exceptionHandler == null)
            {
                throw new ArgumentNullException("exceptionHandler");
            }

            if (trace == null)
            {
                throw new ArgumentNullException("trace");
            }

            if (functionLookup == null)
            {
                throw new ArgumentNullException("functionLookup");
            }

            if (functionInstanceLogger == null)
            {
                throw new ArgumentNullException("functionInstanceLogger");
            }

            if (executor == null)
            {
                throw new ArgumentNullException("executor");
            }

            _queue = queue;
            _queueConfiguration = queueConfiguration;
            _exceptionHandler   = exceptionHandler;
            _trace                  = trace;
            _loggerFactory          = loggerFactory;
            _functionLookup         = functionLookup;
            _functionInstanceLogger = functionInstanceLogger;
            _executor               = executor;
        }
Example #11
0
        public HostMessageListenerFactory(IStorageQueue queue,
                                          IQueueConfiguration queueConfiguration,
                                          IBackgroundExceptionDispatcher backgroundExceptionDispatcher,
                                          TextWriter log,
                                          IFunctionIndexLookup functionLookup,
                                          IFunctionInstanceLogger functionInstanceLogger,
                                          IFunctionExecutor executor)
        {
            if (queue == null)
            {
                throw new ArgumentNullException("queue");
            }

            if (queueConfiguration == null)
            {
                throw new ArgumentNullException("queueConfiguration");
            }

            if (backgroundExceptionDispatcher == null)
            {
                throw new ArgumentNullException("backgroundExceptionDispatcher");
            }

            if (log == null)
            {
                throw new ArgumentNullException("log");
            }

            if (functionLookup == null)
            {
                throw new ArgumentNullException("functionLookup");
            }

            if (functionInstanceLogger == null)
            {
                throw new ArgumentNullException("functionInstanceLogger");
            }

            if (executor == null)
            {
                throw new ArgumentNullException("executor");
            }

            _queue = queue;
            _queueConfiguration            = queueConfiguration;
            _backgroundExceptionDispatcher = backgroundExceptionDispatcher;
            _log                    = log;
            _functionLookup         = functionLookup;
            _functionInstanceLogger = functionInstanceLogger;
            _executor               = executor;
        }
        public HostMessageListenerFactory(IStorageQueue queue,
            IQueueConfiguration queueConfiguration,
            IBackgroundExceptionDispatcher backgroundExceptionDispatcher,
            TextWriter log,
            IFunctionIndexLookup functionLookup,
            IFunctionInstanceLogger functionInstanceLogger,
            IFunctionExecutor executor)
        {
            if (queue == null)
            {
                throw new ArgumentNullException("queue");
            }

            if (queueConfiguration == null)
            {
                throw new ArgumentNullException("queueConfiguration");
            }

            if (backgroundExceptionDispatcher == null)
            {
                throw new ArgumentNullException("backgroundExceptionDispatcher");
            }

            if (log == null)
            {
                throw new ArgumentNullException("log");
            }

            if (functionLookup == null)
            {
                throw new ArgumentNullException("functionLookup");
            }

            if (functionInstanceLogger == null)
            {
                throw new ArgumentNullException("functionInstanceLogger");
            }

            if (executor == null)
            {
                throw new ArgumentNullException("executor");
            }

            _queue = queue;
            _queueConfiguration = queueConfiguration;
            _backgroundExceptionDispatcher = backgroundExceptionDispatcher;
            _log = log;
            _functionLookup = functionLookup;
            _functionInstanceLogger = functionInstanceLogger;
            _executor = executor;
        }
        public HostMessageListenerFactory(IStorageQueue queue,
                                          IQueueConfiguration queueConfiguration,
                                          IWebJobsExceptionHandler exceptionHandler,
                                          ILoggerFactory loggerFactory,
                                          IFunctionIndexLookup functionLookup,
                                          IFunctionInstanceLogger functionInstanceLogger,
                                          IFunctionExecutor executor)
        {
            _queue = queue ?? throw new ArgumentNullException(nameof(queue));
            _queueConfiguration     = queueConfiguration ?? throw new ArgumentNullException(nameof(queueConfiguration));
            _exceptionHandler       = exceptionHandler ?? throw new ArgumentNullException(nameof(exceptionHandler));
            _functionLookup         = functionLookup ?? throw new ArgumentNullException(nameof(functionLookup));
            _functionInstanceLogger = functionInstanceLogger ?? throw new ArgumentNullException(nameof(functionInstanceLogger));
            _executor = executor ?? throw new ArgumentNullException(nameof(executor));

            _loggerFactory = loggerFactory;
        }
 public DashboardLoggingSetup(
     StorageAccountOptions storageAccountOptions,
     IWebJobsExceptionHandler exceptionHandler,
     ILoggerFactory loggerFactory,
     IFunctionInstanceLogger functionInstanceLogger,
     IFunctionExecutor functionExecutor,
     SharedQueueHandler sharedQueueHandler,
     ILoadBalancerQueue storageServices
     )
 {
     _storageAccountOptions  = storageAccountOptions;
     _exceptionHandler       = exceptionHandler;
     _loggerFactory          = loggerFactory;
     _functionInstanceLogger = functionInstanceLogger;
     _functionExecutor       = functionExecutor;
     _sharedQueueHandler     = sharedQueueHandler;
     _storageServices        = storageServices;
 }
Example #15
0
        public HostMessageListenerFactory(
            ILoadBalancerQueue queueFactory,
            string queueName,
            IWebJobsExceptionHandler exceptionHandler,
            ILoggerFactory loggerFactory,
            IFunctionIndexLookup functionLookup,
            IFunctionInstanceLogger functionInstanceLogger,
            IFunctionExecutor executor)
        {
            _queueName              = queueName ?? throw new ArgumentNullException(nameof(queueName));
            _queueFactory           = queueFactory ?? throw new ArgumentNullException(nameof(queueFactory));
            _exceptionHandler       = exceptionHandler ?? throw new ArgumentNullException(nameof(exceptionHandler));
            _functionLookup         = functionLookup ?? throw new ArgumentNullException(nameof(functionLookup));
            _functionInstanceLogger = functionInstanceLogger ?? throw new ArgumentNullException(nameof(functionInstanceLogger));
            _executor = executor ?? throw new ArgumentNullException(nameof(executor));

            _loggerFactory = loggerFactory;
        }
Example #16
0
 public Legacy(
     LegacyConfig storageAccountProvider,
     IWebJobsExceptionHandler exceptionHandler,
     ILoggerFactory loggerFactory,
     IFunctionInstanceLogger functionInstanceLogger,
     IFunctionExecutor functionExecutor,
     SharedQueueHandler sharedQueueHandler,
     ILoadBalancerQueue storageServices
     )
 {
     _storageAccountProvider = storageAccountProvider;
     _exceptionHandler       = exceptionHandler;
     _loggerFactory          = loggerFactory;
     _functionInstanceLogger = functionInstanceLogger;
     _functionExecutor       = functionExecutor;
     _sharedQueueHandler     = sharedQueueHandler;
     _storageServices        = storageServices;
 }
 public FunctionIndexer(
     CloudStorageAccount cloudStorageAccount,
     IFunctionInstanceLogger functionInstanceLogger,
     IFunctionInstanceLookup functionInstanceLookup,
     IFunctionStatisticsWriter statisticsWriter,
     IRecentInvocationIndexWriter recentInvocationsWriter,
     IRecentInvocationIndexByFunctionWriter recentInvocationsByFunctionWriter,
     IRecentInvocationIndexByJobRunWriter recentInvocationsByJobRunWriter,
     IRecentInvocationIndexByParentWriter recentInvocationsByParentWriter)
 {
     _cloudStorageAccount               = cloudStorageAccount;
     _functionInstanceLogger            = functionInstanceLogger;
     _functionInstanceLookup            = functionInstanceLookup;
     _statisticsWriter                  = statisticsWriter;
     _recentInvocationsWriter           = recentInvocationsWriter;
     _recentInvocationsByFunctionWriter = recentInvocationsByFunctionWriter;
     _recentInvocationsByJobRunWriter   = recentInvocationsByJobRunWriter;
     _recentInvocationsByParentWriter   = recentInvocationsByParentWriter;
 }
 public FunctionIndexer(
     CloudStorageAccount cloudStorageAccount,
     IFunctionInstanceLogger functionInstanceLogger,
     IFunctionInstanceLookup functionInstanceLookup,
     IFunctionStatisticsWriter statisticsWriter,
     IRecentInvocationIndexWriter recentInvocationsWriter,
     IRecentInvocationIndexByFunctionWriter recentInvocationsByFunctionWriter,
     IRecentInvocationIndexByJobRunWriter recentInvocationsByJobRunWriter,
     IRecentInvocationIndexByParentWriter recentInvocationsByParentWriter)
 {
     _cloudStorageAccount = cloudStorageAccount;
     _functionInstanceLogger = functionInstanceLogger;
     _functionInstanceLookup = functionInstanceLookup;
     _statisticsWriter = statisticsWriter;
     _recentInvocationsWriter = recentInvocationsWriter;
     _recentInvocationsByFunctionWriter = recentInvocationsByFunctionWriter;
     _recentInvocationsByJobRunWriter = recentInvocationsByJobRunWriter;
     _recentInvocationsByParentWriter = recentInvocationsByParentWriter;
 }
 public JobHostContextFactory(
     IDashboardLoggingSetup dashboardLoggingSetup,
     IFunctionExecutor functionExecutor,
     IFunctionIndexProvider functionIndexProvider,
     ITriggerBindingProvider triggerBindingProvider,
     SingletonManager singletonManager,
     IJobActivator activator,
     IHostIdProvider hostIdProvider,
     INameResolver nameResolver,
     IExtensionRegistry extensions,
     ILoggerFactory loggerFactory,
     IWebJobsExceptionHandler exceptionHandler,
     SharedQueueHandler sharedQueueHandler,
     IOptions <JobHostOptions> jobHostOptions,
     IHostInstanceLogger hostInstanceLogger,
     IFunctionInstanceLogger functionInstanceLogger,
     IFunctionOutputLogger functionOutputLogger,
     IConverterManager converterManager,
     IAsyncCollector <FunctionInstanceLogEntry> eventCollector)
 {
     _dashboardLoggingSetup  = dashboardLoggingSetup;
     _functionExecutor       = functionExecutor;
     _functionIndexProvider  = functionIndexProvider;
     _triggerBindingProvider = triggerBindingProvider;
     _singletonManager       = singletonManager;
     _activator              = activator;
     _hostIdProvider         = hostIdProvider;
     _nameResolver           = nameResolver;
     _extensions             = extensions;
     _loggerFactory          = loggerFactory;
     _exceptionHandler       = exceptionHandler;
     _sharedQueueHandler     = sharedQueueHandler;
     _jobHostOptions         = jobHostOptions;
     _hostInstanceLogger     = hostInstanceLogger;
     _functionInstanceLogger = functionInstanceLogger;
     _functionOutputLogger   = functionOutputLogger;
     _converterManager       = converterManager;
     _eventCollector         = eventCollector;
 }
        public FunctionExecutor(IFunctionInstanceLogger functionInstanceLogger, IFunctionOutputLogger functionOutputLogger,
                                IBackgroundExceptionDispatcher backgroundExceptionDispatcher)
        {
            if (functionInstanceLogger == null)
            {
                throw new ArgumentNullException("functionInstanceLogger");
            }

            if (functionOutputLogger == null)
            {
                throw new ArgumentNullException("functionOutputLogger");
            }

            if (backgroundExceptionDispatcher == null)
            {
                throw new ArgumentNullException("backgroundExceptionDispatcher");
            }

            _functionInstanceLogger        = functionInstanceLogger;
            _functionOutputLogger          = functionOutputLogger;
            _backgroundExceptionDispatcher = backgroundExceptionDispatcher;
        }
        private static IServiceProvider CreateServiceProvider <TResult>(IStorageAccount storageAccount, Type programType,
                                                                        IExtensionTypeLocator extensionTypeLocator, IJobActivator activator,
                                                                        TaskCompletionSource <TResult> taskSource, IFunctionInstanceLogger functionInstanceLogger)
        {
            IStorageAccountProvider storageAccountProvider = new FakeStorageAccountProvider
            {
                StorageAccount = storageAccount
            };
            IServiceBusAccountProvider serviceBusAccountProvider         = new NullServiceBusAccountProvider();
            IHostIdProvider            hostIdProvider                    = new FakeHostIdProvider();
            INameResolver                  nameResolver                  = null;
            IQueueConfiguration            queueConfiguration            = new FakeQueueConfiguration();
            IBackgroundExceptionDispatcher backgroundExceptionDispatcher =
                new TaskBackgroundExceptionDispatcher <TResult>(taskSource);
            ContextAccessor <IMessageEnqueuedWatcher> messageEnqueuedWatcherAccessor =
                new ContextAccessor <IMessageEnqueuedWatcher>();
            ContextAccessor <IBlobWrittenWatcher> blobWrittenWatcherAccessor =
                new ContextAccessor <IBlobWrittenWatcher>();
            ISharedContextProvider  sharedContextProvider  = new SharedContextProvider();
            ITriggerBindingProvider triggerBindingProvider = DefaultTriggerBindingProvider.Create(nameResolver,
                                                                                                  storageAccountProvider, serviceBusAccountProvider, extensionTypeLocator, hostIdProvider,
                                                                                                  queueConfiguration, backgroundExceptionDispatcher, messageEnqueuedWatcherAccessor,
                                                                                                  blobWrittenWatcherAccessor, sharedContextProvider, TextWriter.Null);
            IBindingProvider bindingProvider = DefaultBindingProvider.Create(nameResolver, storageAccountProvider,
                                                                             serviceBusAccountProvider, extensionTypeLocator, messageEnqueuedWatcherAccessor,
                                                                             blobWrittenWatcherAccessor);

            IJobHostContextFactory contextFactory = new FakeJobHostContextFactory
            {
                FunctionIndexProvider = new FunctionIndexProvider(new FakeTypeLocator(programType),
                                                                  triggerBindingProvider, bindingProvider, activator),
                StorageAccountProvider        = storageAccountProvider,
                ServiceBusAccountProvider     = serviceBusAccountProvider,
                BackgroundExceptionDispatcher = backgroundExceptionDispatcher,
                BindingProvider                = bindingProvider,
                ConsoleProvider                = new NullConsoleProvider(),
                HostInstanceLoggerProvider     = new NullHostInstanceLoggerProvider(),
                FunctionInstanceLoggerProvider = new FakeFunctionInstanceLoggerProvider(functionInstanceLogger),
                FunctionOutputLoggerProvider   = new NullFunctionOutputLoggerProvider(),
                HostIdProvider     = hostIdProvider,
                QueueConfiguration = new FakeQueueConfiguration()
            };

            return(new FakeServiceProvider
            {
                ContextFactory = contextFactory
            });
        }
 public FakeFunctionInstanceLoggerProvider(IFunctionInstanceLogger logger)
 {
     _logger = logger;
 }
Example #23
0
 private static IHost CreateConfiguration <TResult>(StorageAccount storageAccount, Type programType, TaskCompletionSource <TResult> taskSource,
                                                    IFunctionInstanceLogger functionInstanceLogger, IExtensionRegistry extensions = null)
 {
     return(CreateConfiguration <TResult>(storageAccount, programType,
                                          new DefaultJobActivator(), taskSource, functionInstanceLogger, extensions));
 }
        internal static async Task <JobHostContext> CreateAndLogHostStartedAsync(
            IStorageAccountProvider storageAccountProvider,
            IFunctionIndexProvider functionIndexProvider,
            IBindingProvider bindingProvider,
            IHostIdProvider hostIdProvider,
            IHostInstanceLoggerProvider hostInstanceLoggerProvider,
            IFunctionInstanceLoggerProvider functionInstanceLoggerProvider,
            IFunctionOutputLoggerProvider functionOutputLoggerProvider,
            IQueueConfiguration queueConfiguration,
            IBackgroundExceptionDispatcher backgroundExceptionDispatcher,
            IConsoleProvider consoleProvider,
            CancellationToken shutdownToken,
            CancellationToken cancellationToken)
        {
            using (CancellationTokenSource combinedCancellationSource =
                       CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, shutdownToken))
            {
                CancellationToken combinedCancellationToken = combinedCancellationSource.Token;

                await WriteSiteExtensionManifestAsync(combinedCancellationToken);

                IStorageAccount dashboardAccount = await storageAccountProvider.GetDashboardAccountAsync(
                    combinedCancellationToken);

                IHostInstanceLogger hostInstanceLogger = await hostInstanceLoggerProvider.GetAsync(
                    combinedCancellationToken);

                IFunctionInstanceLogger functionInstanceLogger = await functionInstanceLoggerProvider.GetAsync(
                    combinedCancellationToken);

                IFunctionOutputLogger functionOutputLogger = await functionOutputLoggerProvider.GetAsync(
                    combinedCancellationToken);

                IFunctionIndex functions = await functionIndexProvider.GetAsync(combinedCancellationToken);

                IListenerFactory functionsListenerFactory = new HostListenerFactory(functions.ReadAll());

                FunctionExecutor executor = new FunctionExecutor(functionInstanceLogger, functionOutputLogger,
                                                                 backgroundExceptionDispatcher);

                TextWriter consoleOut = consoleProvider.Out;

                IFunctionExecutor hostCallExecutor;
                IListener         listener;
                HostOutputMessage hostOutputMessage;

                if (dashboardAccount != null)
                {
                    string hostId = await hostIdProvider.GetHostIdAsync(cancellationToken);

                    string sharedQueueName = HostQueueNames.GetHostQueueName(hostId);
                    IStorageQueueClient dashboardQueueClient       = dashboardAccount.CreateQueueClient();
                    IStorageQueue       sharedQueue                = dashboardQueueClient.GetQueueReference(sharedQueueName);
                    IListenerFactory    sharedQueueListenerFactory = new HostMessageListenerFactory(sharedQueue,
                                                                                                    queueConfiguration, backgroundExceptionDispatcher, consoleOut, functions,
                                                                                                    functionInstanceLogger);

                    Guid             hostInstanceId               = Guid.NewGuid();
                    string           instanceQueueName            = HostQueueNames.GetHostQueueName(hostInstanceId.ToString("N"));
                    IStorageQueue    instanceQueue                = dashboardQueueClient.GetQueueReference(instanceQueueName);
                    IListenerFactory instanceQueueListenerFactory = new HostMessageListenerFactory(instanceQueue,
                                                                                                   queueConfiguration, backgroundExceptionDispatcher, consoleOut, functions,
                                                                                                   functionInstanceLogger);

                    HeartbeatDescriptor heartbeatDescriptor = new HeartbeatDescriptor
                    {
                        SharedContainerName = HostContainerNames.Hosts,
                        SharedDirectoryName = HostDirectoryNames.Heartbeats + "/" + hostId,
                        InstanceBlobName    = hostInstanceId.ToString("N"),
                        ExpirationInSeconds = (int)HeartbeatIntervals.ExpirationInterval.TotalSeconds
                    };
                    IRecurrentCommand heartbeatCommand = new UpdateHostHeartbeatCommand(new HeartbeatCommand(
                                                                                            dashboardAccount,
                                                                                            heartbeatDescriptor.SharedContainerName,
                                                                                            heartbeatDescriptor.SharedDirectoryName + "/" + heartbeatDescriptor.InstanceBlobName));

                    IEnumerable <MethodInfo> indexedMethods = functions.ReadAllMethods();
                    Assembly hostAssembly = GetHostAssembly(indexedMethods);
                    string   displayName  = hostAssembly != null?hostAssembly.GetName().Name : "Unknown";

                    hostOutputMessage = new DataOnlyHostOutputMessage
                    {
                        HostInstanceId      = hostInstanceId,
                        HostDisplayName     = displayName,
                        SharedQueueName     = sharedQueueName,
                        InstanceQueueName   = instanceQueueName,
                        Heartbeat           = heartbeatDescriptor,
                        WebJobRunIdentifier = WebJobRunIdentifier.Current
                    };

                    hostCallExecutor = CreateHostCallExecutor(instanceQueueListenerFactory, heartbeatCommand,
                                                              backgroundExceptionDispatcher, shutdownToken, executor);
                    IListenerFactory hostListenerFactory = new CompositeListenerFactory(functionsListenerFactory,
                                                                                        sharedQueueListenerFactory, instanceQueueListenerFactory);
                    listener = CreateHostListener(hostListenerFactory, heartbeatCommand, backgroundExceptionDispatcher,
                                                  shutdownToken, executor);

                    // Publish this to Azure logging account so that a web dashboard can see it.
                    await LogHostStartedAsync(functions, hostOutputMessage, hostInstanceLogger,
                                              combinedCancellationToken);
                }
                else
                {
                    hostCallExecutor = new ShutdownFunctionExecutor(shutdownToken, executor);

                    IListener factoryListener  = new ListenerFactoryListener(functionsListenerFactory, executor);
                    IListener shutdownListener = new ShutdownListener(shutdownToken, factoryListener);
                    listener = shutdownListener;

                    hostOutputMessage = new DataOnlyHostOutputMessage();
                }

                executor.HostOutputMessage = hostOutputMessage;

                IEnumerable <FunctionDescriptor> descriptors = functions.ReadAllDescriptors();
                int descriptorsCount = descriptors.Count();

                if (descriptorsCount == 0)
                {
                    consoleOut.WriteLine(
                        "No functions found. Try making job classes and methods public.");
                }
                else
                {
                    consoleOut.WriteLine("Found the following functions:");

                    foreach (FunctionDescriptor descriptor in descriptors)
                    {
                        consoleOut.WriteLine(descriptor.FullName);
                    }
                }

                return(new JobHostContext(functions, hostCallExecutor, listener, consoleOut));
            }
        }
        public static async Task <JobHostContext> CreateAndLogHostStartedAsync(
            JobHost host,
            IStorageAccountProvider storageAccountProvider,
            IQueueConfiguration queueConfiguration,
            ITypeLocator typeLocator,
            IJobActivator activator,
            INameResolver nameResolver,
            IConsoleProvider consoleProvider,
            JobHostConfiguration config,
            CancellationToken shutdownToken,
            CancellationToken cancellationToken,
            IHostIdProvider hostIdProvider                                 = null,
            FunctionExecutor functionExecutor                              = null,
            IFunctionIndexProvider functionIndexProvider                   = null,
            IBindingProvider bindingProvider                               = null,
            IHostInstanceLoggerProvider hostInstanceLogerProvider          = null,
            IFunctionInstanceLoggerProvider functionInstanceLoggerProvider = null,
            IFunctionOutputLoggerProvider functionOutputLoggerProvider     = null,
            IBackgroundExceptionDispatcher backgroundExceptionDispatcher   = null,
            SingletonManager singletonManager                              = null)
        {
            if (hostIdProvider == null)
            {
                hostIdProvider = new DynamicHostIdProvider(storageAccountProvider, () => functionIndexProvider);
            }

            IExtensionTypeLocator extensionTypeLocator = new ExtensionTypeLocator(typeLocator);

            if (backgroundExceptionDispatcher == null)
            {
                backgroundExceptionDispatcher = BackgroundExceptionDispatcher.Instance;
            }
            ContextAccessor <IMessageEnqueuedWatcher> messageEnqueuedWatcherAccessor = new ContextAccessor <IMessageEnqueuedWatcher>();
            ContextAccessor <IBlobWrittenWatcher>     blobWrittenWatcherAccessor     = new ContextAccessor <IBlobWrittenWatcher>();
            ISharedContextProvider sharedContextProvider = new SharedContextProvider();

            // Create a wrapper TraceWriter that delegates to both the user
            // TraceWriter specified on Config (if present), as well as to Console
            TraceWriter trace = new ConsoleTraceWriter(config.Tracing, consoleProvider.Out);

            // Register system services with the service container
            config.AddService <INameResolver>(nameResolver);

            ExtensionConfigContext context = new ExtensionConfigContext
            {
                Config = config,
                Trace  = trace,
                Host   = host
            };

            InvokeExtensionConfigProviders(context);

            IExtensionRegistry      extensions             = config.GetExtensions();
            ITriggerBindingProvider triggerBindingProvider = DefaultTriggerBindingProvider.Create(nameResolver,
                                                                                                  storageAccountProvider, extensionTypeLocator, hostIdProvider, queueConfiguration, backgroundExceptionDispatcher,
                                                                                                  messageEnqueuedWatcherAccessor, blobWrittenWatcherAccessor, sharedContextProvider, extensions, trace);

            if (bindingProvider == null)
            {
                bindingProvider = DefaultBindingProvider.Create(nameResolver, storageAccountProvider, extensionTypeLocator, messageEnqueuedWatcherAccessor, blobWrittenWatcherAccessor, extensions);
            }

            DefaultLoggerProvider loggerProvider = new DefaultLoggerProvider(storageAccountProvider, trace);

            if (singletonManager == null)
            {
                singletonManager = new SingletonManager(storageAccountProvider, backgroundExceptionDispatcher, config.Singleton, trace, config.NameResolver);
            }

            using (CancellationTokenSource combinedCancellationSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, shutdownToken))
            {
                CancellationToken combinedCancellationToken = combinedCancellationSource.Token;

                await WriteSiteExtensionManifestAsync(combinedCancellationToken);

                IStorageAccount dashboardAccount = await storageAccountProvider.GetDashboardAccountAsync(combinedCancellationToken);

                IHostInstanceLogger hostInstanceLogger = null;
                if (hostInstanceLogerProvider != null)
                {
                    hostInstanceLogger = await hostInstanceLogerProvider.GetAsync(combinedCancellationToken);
                }
                else
                {
                    hostInstanceLogger = await((IHostInstanceLoggerProvider)loggerProvider).GetAsync(combinedCancellationToken);
                }

                IFunctionInstanceLogger functionInstanceLogger = null;
                if (functionInstanceLoggerProvider != null)
                {
                    functionInstanceLogger = await functionInstanceLoggerProvider.GetAsync(combinedCancellationToken);
                }
                else
                {
                    functionInstanceLogger = (IFunctionInstanceLogger)(await((IFunctionInstanceLoggerProvider)loggerProvider).GetAsync(combinedCancellationToken));
                }

                IFunctionOutputLogger functionOutputLogger = null;
                if (functionOutputLoggerProvider != null)
                {
                    functionOutputLogger = await functionOutputLoggerProvider.GetAsync(combinedCancellationToken);
                }
                else
                {
                    functionOutputLogger = (IFunctionOutputLogger)(await((IFunctionOutputLoggerProvider)loggerProvider).GetAsync(combinedCancellationToken));
                }

                if (functionExecutor == null)
                {
                    functionExecutor = new FunctionExecutor(functionInstanceLogger, functionOutputLogger, backgroundExceptionDispatcher, trace, config.FunctionTimeout);
                }

                if (functionIndexProvider == null)
                {
                    functionIndexProvider = new FunctionIndexProvider(typeLocator, triggerBindingProvider, bindingProvider, activator, functionExecutor, extensions, singletonManager);
                }

                IFunctionIndex functions = await functionIndexProvider.GetAsync(combinedCancellationToken);

                IListenerFactory functionsListenerFactory = new HostListenerFactory(functions.ReadAll(), singletonManager, activator, nameResolver, trace);

                IFunctionExecutor hostCallExecutor;
                IListener         listener;
                HostOutputMessage hostOutputMessage;

                if (dashboardAccount != null)
                {
                    string hostId = await hostIdProvider.GetHostIdAsync(cancellationToken);

                    string sharedQueueName = HostQueueNames.GetHostQueueName(hostId);
                    IStorageQueueClient dashboardQueueClient       = dashboardAccount.CreateQueueClient();
                    IStorageQueue       sharedQueue                = dashboardQueueClient.GetQueueReference(sharedQueueName);
                    IListenerFactory    sharedQueueListenerFactory = new HostMessageListenerFactory(sharedQueue,
                                                                                                    queueConfiguration, backgroundExceptionDispatcher, trace, functions,
                                                                                                    functionInstanceLogger, functionExecutor);

                    Guid             hostInstanceId               = Guid.NewGuid();
                    string           instanceQueueName            = HostQueueNames.GetHostQueueName(hostInstanceId.ToString("N"));
                    IStorageQueue    instanceQueue                = dashboardQueueClient.GetQueueReference(instanceQueueName);
                    IListenerFactory instanceQueueListenerFactory = new HostMessageListenerFactory(instanceQueue,
                                                                                                   queueConfiguration, backgroundExceptionDispatcher, trace, functions,
                                                                                                   functionInstanceLogger, functionExecutor);

                    HeartbeatDescriptor heartbeatDescriptor = new HeartbeatDescriptor
                    {
                        SharedContainerName = HostContainerNames.Hosts,
                        SharedDirectoryName = HostDirectoryNames.Heartbeats + "/" + hostId,
                        InstanceBlobName    = hostInstanceId.ToString("N"),
                        ExpirationInSeconds = (int)HeartbeatIntervals.ExpirationInterval.TotalSeconds
                    };

                    IStorageBlockBlob blob = dashboardAccount.CreateBlobClient()
                                             .GetContainerReference(heartbeatDescriptor.SharedContainerName)
                                             .GetBlockBlobReference(heartbeatDescriptor.SharedDirectoryName + "/" + heartbeatDescriptor.InstanceBlobName);
                    IRecurrentCommand heartbeatCommand = new UpdateHostHeartbeatCommand(new HeartbeatCommand(blob));

                    IEnumerable <MethodInfo> indexedMethods = functions.ReadAllMethods();
                    Assembly hostAssembly = GetHostAssembly(indexedMethods);
                    string   displayName  = hostAssembly != null?hostAssembly.GetName().Name : "Unknown";

                    hostOutputMessage = new DataOnlyHostOutputMessage
                    {
                        HostInstanceId      = hostInstanceId,
                        HostDisplayName     = displayName,
                        SharedQueueName     = sharedQueueName,
                        InstanceQueueName   = instanceQueueName,
                        Heartbeat           = heartbeatDescriptor,
                        WebJobRunIdentifier = WebJobRunIdentifier.Current
                    };

                    hostCallExecutor = CreateHostCallExecutor(instanceQueueListenerFactory, heartbeatCommand,
                                                              backgroundExceptionDispatcher, shutdownToken, functionExecutor);
                    IListenerFactory hostListenerFactory = new CompositeListenerFactory(functionsListenerFactory,
                                                                                        sharedQueueListenerFactory, instanceQueueListenerFactory);
                    listener = CreateHostListener(hostListenerFactory, heartbeatCommand, backgroundExceptionDispatcher, shutdownToken);

                    // Publish this to Azure logging account so that a web dashboard can see it.
                    await LogHostStartedAsync(functions, hostOutputMessage, hostInstanceLogger, combinedCancellationToken);
                }
                else
                {
                    hostCallExecutor = new ShutdownFunctionExecutor(shutdownToken, functionExecutor);

                    IListener factoryListener  = new ListenerFactoryListener(functionsListenerFactory);
                    IListener shutdownListener = new ShutdownListener(shutdownToken, factoryListener);
                    listener = shutdownListener;

                    hostOutputMessage = new DataOnlyHostOutputMessage();
                }

                functionExecutor.HostOutputMessage = hostOutputMessage;

                IEnumerable <FunctionDescriptor> descriptors = functions.ReadAllDescriptors();
                int descriptorsCount = descriptors.Count();

                if (descriptorsCount == 0)
                {
                    trace.Warning(string.Format("No job functions found. Try making your job classes and methods public. {0}",
                                                Constants.ExtensionInitializationMessage), TraceSource.Indexing);
                }
                else
                {
                    StringBuilder functionsTrace = new StringBuilder();
                    functionsTrace.AppendLine("Found the following functions:");

                    foreach (FunctionDescriptor descriptor in descriptors)
                    {
                        functionsTrace.AppendLine(descriptor.FullName);
                    }

                    trace.Info(functionsTrace.ToString(), TraceSource.Indexing);
                }

                return(new JobHostContext(functions, hostCallExecutor, listener, trace));
            }
        }
Example #26
0
 public FakeFunctionInstanceLoggerProvider(IFunctionInstanceLogger logger)
 {
     _logger = logger;
 }
Example #27
0
 public NullFunctionInstanceLoggerProvider(object instance)
 {
     _logger = (IFunctionInstanceLogger)instance;
 }
        // Do the full runtime intitialization. This includes static initialization.
        // This mainly means:
        // - indexing the functions
        // - spinning up the listeners (so connecting to the services)
        public static async Task <JobHostContext> CreateJobHostContextAsync(
            this JobHostConfiguration config,
            ServiceProviderWrapper services, // Results from first phase
            JobHost host,
            CancellationToken shutdownToken,
            CancellationToken cancellationToken)
        {
            FunctionExecutor                           functionExecutor       = services.GetService <FunctionExecutor>();
            IFunctionIndexProvider                     functionIndexProvider  = services.GetService <IFunctionIndexProvider>();
            ITriggerBindingProvider                    triggerBindingProvider = services.GetService <ITriggerBindingProvider>();
            IBindingProvider                           bindingProvider        = services.GetService <IBindingProvider>();
            SingletonManager                           singletonManager       = services.GetService <SingletonManager>();
            IJobActivator                              activator              = services.GetService <IJobActivator>();
            IHostIdProvider                            hostIdProvider         = services.GetService <IHostIdProvider>();
            INameResolver                              nameResolver           = services.GetService <INameResolver>();
            IExtensionRegistry                         extensions             = services.GetExtensions();
            IStorageAccountProvider                    storageAccountProvider = services.GetService <IStorageAccountProvider>();
            ILoggerFactory                             loggerFactory          = services.GetService <ILoggerFactory>();
            IFunctionResultAggregatorFactory           aggregatorFactory      = services.GetService <IFunctionResultAggregatorFactory>();
            IAsyncCollector <FunctionInstanceLogEntry> functionEventCollector = null;

            // Create the aggregator if all the pieces are configured
            IAsyncCollector <FunctionInstanceLogEntry> aggregator = null;

            if (loggerFactory != null && aggregatorFactory != null && config.Aggregator.IsEnabled)
            {
                aggregator = aggregatorFactory.Create(config.Aggregator.BatchSize, config.Aggregator.FlushTimeout, loggerFactory);
            }

            IQueueConfiguration queueConfiguration = services.GetService <IQueueConfiguration>();
            var blobsConfiguration = config.Blobs;

            TraceWriter trace = services.GetService <TraceWriter>();
            IAsyncCollector <FunctionInstanceLogEntry> registeredFunctionEventCollector = services.GetService <IAsyncCollector <FunctionInstanceLogEntry> >();

            if (registeredFunctionEventCollector != null && aggregator != null)
            {
                // If there are both an aggregator and a registered FunctionEventCollector, wrap them in a composite
                functionEventCollector = new CompositeFunctionEventCollector(new[] { registeredFunctionEventCollector, aggregator });
            }
            else
            {
                // Otherwise, take whichever one is null (or use null if both are)
                functionEventCollector = aggregator ?? registeredFunctionEventCollector;
            }

            IWebJobsExceptionHandler exceptionHandler = services.GetService <IWebJobsExceptionHandler>();

            if (exceptionHandler != null)
            {
                exceptionHandler.Initialize(host);
            }

            bool hasFastTableHook   = services.GetService <IAsyncCollector <FunctionInstanceLogEntry> >() != null;
            bool noDashboardStorage = config.DashboardConnectionString == null;

            // Only testing will override these interfaces.
            IHostInstanceLoggerProvider     hostInstanceLoggerProvider     = services.GetService <IHostInstanceLoggerProvider>();
            IFunctionInstanceLoggerProvider functionInstanceLoggerProvider = services.GetService <IFunctionInstanceLoggerProvider>();
            IFunctionOutputLoggerProvider   functionOutputLoggerProvider   = services.GetService <IFunctionOutputLoggerProvider>();

            if (hostInstanceLoggerProvider == null && functionInstanceLoggerProvider == null && functionOutputLoggerProvider == null)
            {
                if (hasFastTableHook && noDashboardStorage)
                {
                    var loggerProvider = new FastTableLoggerProvider(trace);
                    hostInstanceLoggerProvider     = loggerProvider;
                    functionInstanceLoggerProvider = loggerProvider;
                    functionOutputLoggerProvider   = loggerProvider;
                }
                else
                {
                    var loggerProvider = new DefaultLoggerProvider(storageAccountProvider, trace);
                    hostInstanceLoggerProvider     = loggerProvider;
                    functionInstanceLoggerProvider = loggerProvider;
                    functionOutputLoggerProvider   = loggerProvider;
                }
            }

            using (CancellationTokenSource combinedCancellationSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, shutdownToken))
            {
                CancellationToken combinedCancellationToken = combinedCancellationSource.Token;

                await WriteSiteExtensionManifestAsync(combinedCancellationToken);

                IStorageAccount dashboardAccount = await storageAccountProvider.GetDashboardAccountAsync(combinedCancellationToken);

                IHostInstanceLogger hostInstanceLogger = await hostInstanceLoggerProvider.GetAsync(combinedCancellationToken);

                IFunctionInstanceLogger functionInstanceLogger = await functionInstanceLoggerProvider.GetAsync(combinedCancellationToken);

                IFunctionOutputLogger functionOutputLogger = await functionOutputLoggerProvider.GetAsync(combinedCancellationToken);

                if (functionExecutor == null)
                {
                    var extensionRegistry     = config.GetService <IExtensionRegistry>();
                    var globalFunctionFilters = extensionRegistry.GetFunctionFilters();

                    functionExecutor = new FunctionExecutor(functionInstanceLogger, functionOutputLogger, exceptionHandler, trace, functionEventCollector, loggerFactory, globalFunctionFilters);
                    services.AddService(functionExecutor);
                }

                if (functionIndexProvider == null)
                {
                    functionIndexProvider = new FunctionIndexProvider(
                        services.GetService <ITypeLocator>(),
                        triggerBindingProvider,
                        bindingProvider,
                        activator,
                        functionExecutor,
                        extensions,
                        singletonManager,
                        trace,
                        loggerFactory);

                    // Important to set this so that the func we passed to DynamicHostIdProvider can pick it up.
                    services.AddService <IFunctionIndexProvider>(functionIndexProvider);
                }

                IFunctionIndex functions = await functionIndexProvider.GetAsync(combinedCancellationToken);

                IListenerFactory functionsListenerFactory = new HostListenerFactory(functions.ReadAll(), singletonManager, activator, nameResolver, trace, loggerFactory);

                IFunctionExecutor hostCallExecutor;
                IListener         listener;
                HostOutputMessage hostOutputMessage;

                string hostId = await hostIdProvider.GetHostIdAsync(cancellationToken);

                if (string.Compare(config.HostId, hostId, StringComparison.OrdinalIgnoreCase) != 0)
                {
                    // if this isn't a static host ID, provide the HostId on the config
                    // so it is accessible
                    config.HostId = hostId;
                }

                if (dashboardAccount == null)
                {
                    hostCallExecutor = new ShutdownFunctionExecutor(shutdownToken, functionExecutor);

                    IListener factoryListener  = new ListenerFactoryListener(functionsListenerFactory);
                    IListener shutdownListener = new ShutdownListener(shutdownToken, factoryListener);
                    listener = shutdownListener;

                    hostOutputMessage = new DataOnlyHostOutputMessage();
                }
                else
                {
                    string sharedQueueName = HostQueueNames.GetHostQueueName(hostId);
                    IStorageQueueClient dashboardQueueClient       = dashboardAccount.CreateQueueClient();
                    IStorageQueue       sharedQueue                = dashboardQueueClient.GetQueueReference(sharedQueueName);
                    IListenerFactory    sharedQueueListenerFactory = new HostMessageListenerFactory(sharedQueue,
                                                                                                    queueConfiguration, exceptionHandler, trace, loggerFactory, functions,
                                                                                                    functionInstanceLogger, functionExecutor);

                    Guid             hostInstanceId               = Guid.NewGuid();
                    string           instanceQueueName            = HostQueueNames.GetHostQueueName(hostInstanceId.ToString("N"));
                    IStorageQueue    instanceQueue                = dashboardQueueClient.GetQueueReference(instanceQueueName);
                    IListenerFactory instanceQueueListenerFactory = new HostMessageListenerFactory(instanceQueue,
                                                                                                   queueConfiguration, exceptionHandler, trace, loggerFactory, functions,
                                                                                                   functionInstanceLogger, functionExecutor);

                    HeartbeatDescriptor heartbeatDescriptor = new HeartbeatDescriptor
                    {
                        SharedContainerName = HostContainerNames.Hosts,
                        SharedDirectoryName = HostDirectoryNames.Heartbeats + "/" + hostId,
                        InstanceBlobName    = hostInstanceId.ToString("N"),
                        ExpirationInSeconds = (int)HeartbeatIntervals.ExpirationInterval.TotalSeconds
                    };

                    IStorageBlockBlob blob = dashboardAccount.CreateBlobClient()
                                             .GetContainerReference(heartbeatDescriptor.SharedContainerName)
                                             .GetBlockBlobReference(heartbeatDescriptor.SharedDirectoryName + "/" + heartbeatDescriptor.InstanceBlobName);
                    IRecurrentCommand heartbeatCommand = new UpdateHostHeartbeatCommand(new HeartbeatCommand(blob));

                    IEnumerable <MethodInfo> indexedMethods = functions.ReadAllMethods();
                    Assembly hostAssembly = GetHostAssembly(indexedMethods);
                    string   displayName  = hostAssembly != null?AssemblyNameCache.GetName(hostAssembly).Name : "Unknown";

                    hostOutputMessage = new DataOnlyHostOutputMessage
                    {
                        HostInstanceId      = hostInstanceId,
                        HostDisplayName     = displayName,
                        SharedQueueName     = sharedQueueName,
                        InstanceQueueName   = instanceQueueName,
                        Heartbeat           = heartbeatDescriptor,
                        WebJobRunIdentifier = WebJobRunIdentifier.Current
                    };

                    hostCallExecutor = CreateHostCallExecutor(instanceQueueListenerFactory, heartbeatCommand,
                                                              exceptionHandler, shutdownToken, functionExecutor);
                    IListenerFactory hostListenerFactory = new CompositeListenerFactory(functionsListenerFactory,
                                                                                        sharedQueueListenerFactory, instanceQueueListenerFactory);
                    listener = CreateHostListener(hostListenerFactory, heartbeatCommand, exceptionHandler, shutdownToken);

                    // Publish this to Azure logging account so that a web dashboard can see it.
                    await LogHostStartedAsync(functions, hostOutputMessage, hostInstanceLogger, combinedCancellationToken);
                }

                functionExecutor.HostOutputMessage = hostOutputMessage;

                IEnumerable <FunctionDescriptor> descriptors = functions.ReadAllDescriptors();
                int descriptorsCount = descriptors.Count();

                ILogger startupLogger = loggerFactory?.CreateLogger(LogCategories.Startup);

                if (config.UsingDevelopmentSettings)
                {
                    string msg = "Development settings applied";
                    trace.Verbose(msg);
                    startupLogger?.LogDebug(msg);
                }

                if (descriptorsCount == 0)
                {
                    string msg = string.Format("No job functions found. Try making your job classes and methods public. {0}",
                                               Constants.ExtensionInitializationMessage);

                    trace.Warning(msg, Host.TraceSource.Indexing);
                    startupLogger?.LogWarning(msg);
                }
                else
                {
                    StringBuilder functionsTrace = new StringBuilder();
                    functionsTrace.AppendLine("Found the following functions:");

                    foreach (FunctionDescriptor descriptor in descriptors)
                    {
                        functionsTrace.AppendLine(descriptor.FullName);
                    }
                    string msg = functionsTrace.ToString();
                    trace.Info(msg, Host.TraceSource.Indexing);
                    startupLogger?.LogInformation(msg);
                }

                return(new JobHostContext(
                           functions,
                           hostCallExecutor,
                           listener,
                           trace,
                           functionEventCollector,
                           loggerFactory));
            }
        }
 public FastTableLoggerProvider(TraceWriter trace)
 {
     _hostInstanceLogger        = new NullHostInstanceLogger();
     _traceWriterFunctionLogger = new TraceWriterFunctionInstanceLogger(trace);
 }
        private static IServiceProvider CreateServiceProvider <TResult>(IStorageAccount storageAccount, Type programType,
                                                                        IExtensionTypeLocator extensionTypeLocator, IJobActivator activator,
                                                                        TaskCompletionSource <TResult> taskSource, IFunctionInstanceLogger functionInstanceLogger, IExtensionRegistry extensions = null)
        {
            IStorageAccountProvider storageAccountProvider = new FakeStorageAccountProvider
            {
                StorageAccount = storageAccount
            };
            IHostIdProvider                hostIdProvider                = new FakeHostIdProvider();
            INameResolver                  nameResolver                  = null;
            IQueueConfiguration            queueConfiguration            = new FakeQueueConfiguration(storageAccountProvider);
            IBackgroundExceptionDispatcher backgroundExceptionDispatcher =
                new TaskBackgroundExceptionDispatcher <TResult>(taskSource);
            ContextAccessor <IMessageEnqueuedWatcher> messageEnqueuedWatcherAccessor =
                new ContextAccessor <IMessageEnqueuedWatcher>();
            ContextAccessor <IBlobWrittenWatcher> blobWrittenWatcherAccessor =
                new ContextAccessor <IBlobWrittenWatcher>();
            ISharedContextProvider sharedContextProvider = new SharedContextProvider();

            if (extensions == null)
            {
                extensions = new DefaultExtensionRegistry();
            }

            ITriggerBindingProvider triggerBindingProvider = DefaultTriggerBindingProvider.Create(nameResolver,
                                                                                                  storageAccountProvider, extensionTypeLocator, hostIdProvider,
                                                                                                  queueConfiguration, backgroundExceptionDispatcher, messageEnqueuedWatcherAccessor,
                                                                                                  blobWrittenWatcherAccessor, sharedContextProvider, extensions, TextWriter.Null);
            IBindingProvider bindingProvider = DefaultBindingProvider.Create(nameResolver, storageAccountProvider,
                                                                             extensionTypeLocator, messageEnqueuedWatcherAccessor,
                                                                             blobWrittenWatcherAccessor, extensions);

            IFunctionInstanceLoggerProvider functionInstanceLoggerProvider = new NullFunctionInstanceLoggerProvider();
            IFunctionOutputLoggerProvider   functionOutputLoggerProvider   = new NullFunctionOutputLoggerProvider();
            Task <IFunctionOutputLogger>    task = functionOutputLoggerProvider.GetAsync(CancellationToken.None);

            task.Wait();
            IFunctionOutputLogger functionOutputLogger = task.Result;
            FunctionExecutor      executor             = new FunctionExecutor(functionInstanceLogger, functionOutputLogger, backgroundExceptionDispatcher);

            ITypeLocator          typeLocator           = new FakeTypeLocator(programType);
            FunctionIndexProvider functionIndexProvider = new FunctionIndexProvider(
                typeLocator, triggerBindingProvider, bindingProvider,
                activator, executor, extensions);

            IJobHostContextFactory contextFactory = new FakeJobHostContextFactory
            {
                TypeLocator                    = typeLocator,
                FunctionIndexProvider          = functionIndexProvider,
                StorageAccountProvider         = storageAccountProvider,
                BackgroundExceptionDispatcher  = backgroundExceptionDispatcher,
                BindingProvider                = bindingProvider,
                ConsoleProvider                = new NullConsoleProvider(),
                HostInstanceLoggerProvider     = new NullHostInstanceLoggerProvider(),
                FunctionExecutor               = executor,
                FunctionInstanceLoggerProvider = functionInstanceLoggerProvider,
                FunctionOutputLoggerProvider   = functionOutputLoggerProvider,
                HostIdProvider                 = hostIdProvider,
                QueueConfiguration             = queueConfiguration
            };

            return(new FakeServiceProvider
            {
                ContextFactory = contextFactory
            });
        }
Example #31
0
 public FastTableLoggerProvider(TraceWriter trace)
 {
     _hostInstanceLogger = new NullHostInstanceLogger();
     _traceWriterFunctionLogger = new TraceWriterFunctionInstanceLogger(trace);
 }
 public FastTableLoggerProvider(ILoggerFactory loggerFactory)
 {
     _hostInstanceLogger = new NullHostInstanceLogger();
     _functionLogger     = new FunctionInstanceLogger(loggerFactory);
 }
Example #33
0
        private static JobHostConfiguration CreateConfiguration <TResult>(IStorageAccount storageAccount, Type programType,
                                                                          IExtensionTypeLocator extensionTypeLocator, IJobActivator activator,
                                                                          TaskCompletionSource <TResult> taskSource, IFunctionInstanceLogger functionInstanceLogger, IExtensionRegistry extensions = null)
        {
            IStorageAccountProvider storageAccountProvider = new FakeStorageAccountProvider
            {
                StorageAccount = storageAccount
            };
            IHostIdProvider          hostIdProvider   = new FakeHostIdProvider();
            IWebJobsExceptionHandler exceptionHandler = new TaskBackgroundExceptionHandler <TResult>(taskSource);

            return(TestHelpers.NewConfig(
                       programType,
                       new FakeQueueConfiguration(storageAccountProvider),
                       storageAccountProvider,
                       extensionTypeLocator,
                       activator,
                       extensions,
                       exceptionHandler,
                       new NullFunctionInstanceLoggerProvider(functionInstanceLogger),
                       new NullHostInstanceLoggerProvider(),
                       new NullFunctionOutputLoggerProvider()
                       ));
        }