コード例 #1
1
        public static ITriggerBindingProvider Create(INameResolver nameResolver,
            IStorageAccountProvider storageAccountProvider,
            IExtensionTypeLocator extensionTypeLocator,
            IHostIdProvider hostIdProvider,
            IQueueConfiguration queueConfiguration,
            IBackgroundExceptionDispatcher backgroundExceptionDispatcher,
            IContextSetter<IMessageEnqueuedWatcher> messageEnqueuedWatcherSetter,
            IContextSetter<IBlobWrittenWatcher> blobWrittenWatcherSetter,
            ISharedContextProvider sharedContextProvider,
            IExtensionRegistry extensions,
            TextWriter log)
        {
            List<ITriggerBindingProvider> innerProviders = new List<ITriggerBindingProvider>();
            innerProviders.Add(new QueueTriggerAttributeBindingProvider(nameResolver, storageAccountProvider,
                queueConfiguration, backgroundExceptionDispatcher, messageEnqueuedWatcherSetter,
                sharedContextProvider, log));
            innerProviders.Add(new BlobTriggerAttributeBindingProvider(nameResolver, storageAccountProvider,
                extensionTypeLocator, hostIdProvider, queueConfiguration, backgroundExceptionDispatcher,
                blobWrittenWatcherSetter, messageEnqueuedWatcherSetter, sharedContextProvider, log));

            // add any registered extension binding providers
            foreach (ITriggerBindingProvider provider in extensions.GetExtensions(typeof(ITriggerBindingProvider)))
            {
                innerProviders.Add(provider);
            }

            return new CompositeTriggerBindingProvider(innerProviders);
        }
コード例 #2
0
 public HeartbeatListener(IRecurrentCommand heartbeatCommand,
     IBackgroundExceptionDispatcher backgroundExceptionDispatcher, IListener innerListener)
 {
     _heartbeatCommand = heartbeatCommand;
     _innerListener = innerListener;
     _timer = CreateTimer(backgroundExceptionDispatcher);
 }
コード例 #3
0
 public HeartbeatListener(IRecurrentCommand heartbeatCommand,
                          IBackgroundExceptionDispatcher backgroundExceptionDispatcher, IListener innerListener)
 {
     _heartbeatCommand = heartbeatCommand;
     _innerListener    = innerListener;
     _timer            = CreateTimer(backgroundExceptionDispatcher);
 }
コード例 #4
0
 public HeartbeatFunctionExecutor(IRecurrentCommand heartbeatCommand,
     IBackgroundExceptionDispatcher backgroundExceptionDispatcher, IFunctionExecutor innerExecutor)
 {
     _heartbeatCommand = heartbeatCommand;
     _backgroundExceptionDispatcher = backgroundExceptionDispatcher;
     _innerExecutor = innerExecutor;
 }
コード例 #5
0
        public Task <JobHostContext> CreateAndLogHostStartedAsync(CancellationToken shutdownToken,
                                                                  CancellationToken cancellationToken)
        {
            IFunctionIndexProvider functionIndexProvider = null;
            IHostIdProvider        hostIdProvider        = _hostId != null ? (IHostIdProvider) new FixedHostIdProvider(_hostId)
                : new DynamicHostIdProvider(_storageAccountProvider, () => functionIndexProvider);
            IExtensionTypeLocator                     extensionTypeLocator           = new ExtensionTypeLocator(_typeLocator);
            IBackgroundExceptionDispatcher            backgroundExceptionDispatcher  = BackgroundExceptionDispatcher.Instance;
            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, _consoleProvider.Out);
            IBindingProvider bindingProvider = DefaultBindingProvider.Create(_nameResolver, _storageAccountProvider,
                                                                             _serviceBusAccountProvider, extensionTypeLocator, messageEnqueuedWatcherAccessor,
                                                                             blobWrittenWatcherAccessor);

            functionIndexProvider = new FunctionIndexProvider(_typeLocator, triggerBindingProvider, bindingProvider,
                                                              _activator);
            DefaultLoggerProvider loggerProvider = new DefaultLoggerProvider(_storageAccountProvider);

            return(CreateAndLogHostStartedAsync(_storageAccountProvider, functionIndexProvider, bindingProvider,
                                                hostIdProvider, loggerProvider, loggerProvider, loggerProvider, _queueConfiguration,
                                                backgroundExceptionDispatcher, _consoleProvider,
                                                shutdownToken, cancellationToken));
        }
コード例 #6
0
        public static ITriggerBindingProvider Create(INameResolver nameResolver,
                                                     IStorageAccountProvider storageAccountProvider,
                                                     IServiceBusAccountProvider serviceBusAccountProvider,
                                                     IExtensionTypeLocator extensionTypeLocator,
                                                     IHostIdProvider hostIdProvider,
                                                     IQueueConfiguration queueConfiguration,
                                                     IBackgroundExceptionDispatcher backgroundExceptionDispatcher,
                                                     IContextSetter <IMessageEnqueuedWatcher> messageEnqueuedWatcherSetter,
                                                     IContextSetter <IBlobWrittenWatcher> blobWrittenWatcherSetter,
                                                     ISharedContextProvider sharedContextProvider,
                                                     TextWriter log)
        {
            List <ITriggerBindingProvider> innerProviders = new List <ITriggerBindingProvider>();

            innerProviders.Add(new QueueTriggerAttributeBindingProvider(nameResolver, storageAccountProvider,
                                                                        queueConfiguration, backgroundExceptionDispatcher, messageEnqueuedWatcherSetter,
                                                                        sharedContextProvider, log));
            innerProviders.Add(new BlobTriggerAttributeBindingProvider(nameResolver, storageAccountProvider,
                                                                       extensionTypeLocator, hostIdProvider, queueConfiguration, backgroundExceptionDispatcher,
                                                                       blobWrittenWatcherSetter, messageEnqueuedWatcherSetter, sharedContextProvider, log));

            Type serviceBusProviderType = ServiceBusExtensionTypeLoader.Get(
                "Microsoft.Azure.WebJobs.ServiceBus.Triggers.ServiceBusTriggerAttributeBindingProvider");

            if (serviceBusProviderType != null)
            {
                ITriggerBindingProvider serviceBusAttributeBindingProvider =
                    (ITriggerBindingProvider)Activator.CreateInstance(serviceBusProviderType, nameResolver,
                                                                      serviceBusAccountProvider);
                innerProviders.Add(serviceBusAttributeBindingProvider);
            }

            return(new CompositeTriggerBindingProvider(innerProviders));
        }
コード例 #7
0
 public static ITaskSeriesTimer CreateTimer(IRecurrentCommand command, TimeSpan normalInterval,
     TimeSpan minimumInterval, IBackgroundExceptionDispatcher backgroundExceptionDispatcher)
 {
     IDelayStrategy delayStrategy = new LinearSpeedupStrategy(normalInterval, minimumInterval);
     ITaskSeriesCommand timerCommand = new RecurrentTaskSeriesCommand(command, delayStrategy);
     return new TaskSeriesTimer(timerCommand, backgroundExceptionDispatcher, Task.Delay(normalInterval));
 }
コード例 #8
0
 public static ITaskSeriesTimer CreateTimer(IRecurrentCommand command, TimeSpan initialInterval,
     TimeSpan delayInterval, IBackgroundExceptionDispatcher backgroundExceptionDispatcher)
 {
     IDelayStrategy delayStrategy = new FixedDelayStrategy(delayInterval);
     ITaskSeriesCommand timerCommand = new RecurrentTaskSeriesCommand(command, delayStrategy);
     return new TaskSeriesTimer(timerCommand, backgroundExceptionDispatcher, Task.Delay(initialInterval));
 }
コード例 #9
0
        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;
        }
コード例 #10
0
 public SharedBlobListener(IStorageAccount storageAccount,
                           IBackgroundExceptionDispatcher backgroundExceptionDispatcher)
 {
     _strategy = CreateStrategy(storageAccount);
     // Start the first iteration immediately.
     _timer = new TaskSeriesTimer(_strategy, backgroundExceptionDispatcher, initialWait: Task.Delay(0));
 }
コード例 #11
0
 public SharedBlobListener(IStorageAccount storageAccount,
     IBackgroundExceptionDispatcher backgroundExceptionDispatcher)
 {
     _strategy = CreateStrategy(storageAccount);
     // Start the first iteration immediately.
     _timer = new TaskSeriesTimer(_strategy, backgroundExceptionDispatcher, initialWait: Task.Delay(0));
 }
コード例 #12
0
 public HeartbeatFunctionExecutor(IRecurrentCommand heartbeatCommand,
                                  IBackgroundExceptionDispatcher backgroundExceptionDispatcher, IFunctionExecutor innerExecutor)
 {
     _heartbeatCommand = heartbeatCommand;
     _backgroundExceptionDispatcher = backgroundExceptionDispatcher;
     _innerExecutor = innerExecutor;
 }
コード例 #13
0
        public static ITriggerBindingProvider Create(INameResolver nameResolver,
                                                     IStorageAccountProvider storageAccountProvider,
                                                     IExtensionTypeLocator extensionTypeLocator,
                                                     IHostIdProvider hostIdProvider,
                                                     IQueueConfiguration queueConfiguration,
                                                     IBackgroundExceptionDispatcher backgroundExceptionDispatcher,
                                                     IContextSetter <IMessageEnqueuedWatcher> messageEnqueuedWatcherSetter,
                                                     IContextSetter <IBlobWrittenWatcher> blobWrittenWatcherSetter,
                                                     ISharedContextProvider sharedContextProvider,
                                                     IExtensionRegistry extensions,
                                                     TextWriter log)
        {
            List <ITriggerBindingProvider> innerProviders = new List <ITriggerBindingProvider>();

            innerProviders.Add(new QueueTriggerAttributeBindingProvider(nameResolver, storageAccountProvider,
                                                                        queueConfiguration, backgroundExceptionDispatcher, messageEnqueuedWatcherSetter,
                                                                        sharedContextProvider, log));
            innerProviders.Add(new BlobTriggerAttributeBindingProvider(nameResolver, storageAccountProvider,
                                                                       extensionTypeLocator, hostIdProvider, queueConfiguration, backgroundExceptionDispatcher,
                                                                       blobWrittenWatcherSetter, messageEnqueuedWatcherSetter, sharedContextProvider, log));

            // add any registered extension binding providers
            foreach (ITriggerBindingProvider provider in extensions.GetExtensions(typeof(ITriggerBindingProvider)))
            {
                innerProviders.Add(provider);
            }

            return(new CompositeTriggerBindingProvider(innerProviders));
        }
コード例 #14
0
        public SharedBlobQueueListenerFactory(
            SharedQueueWatcher sharedQueueWatcher,
            IStorageQueueClient queueClient,
            IStorageQueue hostBlobTriggerQueue,
            IStorageBlobClient blobClient,
            IQueueConfiguration queueConfiguration,
            IBackgroundExceptionDispatcher backgroundExceptionDispatcher,
            TextWriter log,
            IBlobWrittenWatcher blobWrittenWatcher)
        {
            if (sharedQueueWatcher == null)
            {
                throw new ArgumentNullException("sharedQueueWatcher");
            }

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

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

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

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

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

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

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

            _sharedQueueWatcher            = sharedQueueWatcher;
            _queueClient                   = queueClient;
            _hostBlobTriggerQueue          = hostBlobTriggerQueue;
            _blobClient                    = blobClient;
            _queueConfiguration            = queueConfiguration;
            _backgroundExceptionDispatcher = backgroundExceptionDispatcher;
            _log = log;
            _blobWrittenWatcher = blobWrittenWatcher;
        }
コード例 #15
0
 // Begin watchers.
 public ValueWatcher(IReadOnlyDictionary<string, IWatcher> watches, CloudBlockBlob blobResults,
     TextWriter consoleOutput, IBackgroundExceptionDispatcher backgroundExceptionDispatcher)
 {
     ValueWatcherCommand command = new ValueWatcherCommand(watches, blobResults, consoleOutput);
     _command = command;
     _timer = ValueWatcherCommand.CreateTimer(command, backgroundExceptionDispatcher);
     _timer.Start();
 }
コード例 #16
0
        public static ITaskSeriesTimer CreateTimer(IRecurrentCommand command, TimeSpan normalInterval,
                                                   TimeSpan minimumInterval, IBackgroundExceptionDispatcher backgroundExceptionDispatcher)
        {
            IDelayStrategy     delayStrategy = new LinearSpeedupStrategy(normalInterval, minimumInterval);
            ITaskSeriesCommand timerCommand  = new RecurrentTaskSeriesCommand(command, delayStrategy);

            return(new TaskSeriesTimer(timerCommand, backgroundExceptionDispatcher, Task.Delay(normalInterval)));
        }
コード例 #17
0
 public SingletonManager(IStorageBlobClient blobClient, IBackgroundExceptionDispatcher backgroundExceptionDispatcher, SingletonConfiguration config, TraceWriter trace)
 {
     _backgroundExceptionDispatcher = backgroundExceptionDispatcher;
     _directory = blobClient.GetContainerReference(HostContainerNames.Hosts)
                  .GetDirectoryReference(HostDirectoryNames.SingletonLocks);
     _config = config;
     _trace  = trace;
 }
コード例 #18
0
 public SingletonManager(IStorageBlobClient blobClient, IBackgroundExceptionDispatcher backgroundExceptionDispatcher, SingletonConfiguration config, TraceWriter trace)
 {
     _backgroundExceptionDispatcher = backgroundExceptionDispatcher;
     _directory = blobClient.GetContainerReference(HostContainerNames.Hosts)
                            .GetDirectoryReference(HostDirectoryNames.SingletonLocks);
     _config = config;
     _trace = trace;
 }
コード例 #19
0
 public SingletonManager(IStorageAccountProvider accountProvider, IBackgroundExceptionDispatcher backgroundExceptionDispatcher, SingletonConfiguration config, TraceWriter trace, INameResolver nameResolver = null)
 {
     _accountProvider = accountProvider;
     _nameResolver    = nameResolver;
     _backgroundExceptionDispatcher = backgroundExceptionDispatcher;
     _config = config;
     _trace  = trace;
 }
コード例 #20
0
 public SingletonManager(IStorageAccountProvider accountProvider, IBackgroundExceptionDispatcher backgroundExceptionDispatcher, SingletonConfiguration config, TraceWriter trace, INameResolver nameResolver = null)
 {
     _accountProvider = accountProvider;
     _nameResolver = nameResolver;
     _backgroundExceptionDispatcher = backgroundExceptionDispatcher;
     _config = config;
     _trace = trace;
 }
コード例 #21
0
        // Begin watchers.
        public ValueWatcher(IReadOnlyDictionary <string, IWatcher> watches, CloudBlockBlob blobResults,
                            TextWriter consoleOutput, IBackgroundExceptionDispatcher backgroundExceptionDispatcher)
        {
            ValueWatcherCommand command = new ValueWatcherCommand(watches, blobResults, consoleOutput);

            _command = command;
            _timer   = ValueWatcherCommand.CreateTimer(command, backgroundExceptionDispatcher);
            _timer.Start();
        }
コード例 #22
0
        public QueueTriggerBinding(string parameterName,
            IStorageQueue queue,
            ITriggerDataArgumentBinding<IStorageQueueMessage> argumentBinding,
            IQueueConfiguration queueConfiguration,
            IBackgroundExceptionDispatcher backgroundExceptionDispatcher,
            IContextSetter<IMessageEnqueuedWatcher> messageEnqueuedWatcherSetter,
            ISharedContextProvider sharedContextProvider,
            TextWriter log)
        {
            if (queue == null)
            {
                throw new ArgumentNullException("queue");
            }

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

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

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

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

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

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

            _parameterName = parameterName;
            _queue = queue;
            _argumentBinding = argumentBinding;
            _bindingDataContract = CreateBindingDataContract(argumentBinding);
            _queueConfiguration = queueConfiguration;
            _backgroundExceptionDispatcher = backgroundExceptionDispatcher;
            _messageEnqueuedWatcherSetter = messageEnqueuedWatcherSetter;
            _sharedContextProvider = sharedContextProvider;
            _log = log;
            _converter = CreateConverter(queue);
        }
コード例 #23
0
        public QueueTriggerBinding(string parameterName,
                                   IStorageQueue queue,
                                   ITriggerDataArgumentBinding <IStorageQueueMessage> argumentBinding,
                                   IQueueConfiguration queueConfiguration,
                                   IBackgroundExceptionDispatcher backgroundExceptionDispatcher,
                                   IContextSetter <IMessageEnqueuedWatcher> messageEnqueuedWatcherSetter,
                                   ISharedContextProvider sharedContextProvider,
                                   TextWriter log)
        {
            if (queue == null)
            {
                throw new ArgumentNullException("queue");
            }

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

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

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

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

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

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

            _parameterName                 = parameterName;
            _queue                         = queue;
            _argumentBinding               = argumentBinding;
            _bindingDataContract           = CreateBindingDataContract(argumentBinding);
            _queueConfiguration            = queueConfiguration;
            _backgroundExceptionDispatcher = backgroundExceptionDispatcher;
            _messageEnqueuedWatcherSetter  = messageEnqueuedWatcherSetter;
            _sharedContextProvider         = sharedContextProvider;
            _log       = log;
            _converter = CreateConverter(queue);
        }
コード例 #24
0
        private static ValueWatcher CreateValueWatcher(IReadOnlyDictionary <string, IWatcher> watches,
                                                       CloudBlockBlob parameterLogBlob, TextWriter consoleOutput,
                                                       IBackgroundExceptionDispatcher backgroundExceptionDispatcher)
        {
            if (parameterLogBlob == null)
            {
                return(null);
            }

            return(new ValueWatcher(watches, parameterLogBlob, consoleOutput, backgroundExceptionDispatcher));
        }
コード例 #25
0
        private ITaskSeriesTimer CreateLeaseRenewalTimer(IStorageBlockBlob leaseBlob, string leaseId, string lockId, TimeSpan leasePeriod,
                                                         IBackgroundExceptionDispatcher backgroundExceptionDispatcher)
        {
            // renew the lease when it is halfway to expiring
            TimeSpan normalUpdateInterval = new TimeSpan(leasePeriod.Ticks / 2);

            IDelayStrategy     speedupStrategy = new LinearSpeedupStrategy(normalUpdateInterval, MinimumLeaseRenewalInterval);
            ITaskSeriesCommand command         = new RenewLeaseCommand(leaseBlob, leaseId, lockId, speedupStrategy, _trace);

            return(new TaskSeriesTimer(command, backgroundExceptionDispatcher, Task.Delay(normalUpdateInterval)));
        }
コード例 #26
0
        private static ITaskSeriesTimer CreateUpdateMessageVisibilityTimer(IStorageQueue queue,
                                                                           IStorageQueueMessage message, TimeSpan visibilityTimeout,
                                                                           IBackgroundExceptionDispatcher backgroundExceptionDispatcher)
        {
            // Update a message's visibility when it is halfway to expiring.
            TimeSpan normalUpdateInterval = new TimeSpan(visibilityTimeout.Ticks / 2);

            IDelayStrategy     speedupStrategy = new LinearSpeedupStrategy(normalUpdateInterval, TimeSpan.FromMinutes(1));
            ITaskSeriesCommand command         = new UpdateQueueMessageVisibilityCommand(queue, message, visibilityTimeout, speedupStrategy);

            return(new TaskSeriesTimer(command, backgroundExceptionDispatcher, Task.Delay(normalUpdateInterval)));
        }
コード例 #27
0
        public void Constructor_IfBackgroundExceptionDispatcherIsNull_Throws()
        {
            // Arrange
            ITaskSeriesCommand             command = CreateDummyCommand();
            IBackgroundExceptionDispatcher backgroundExceptionDispatcher = null;
            Task initialWait = Task.FromResult(0);

            // Act & Assert
            ExceptionAssert.ThrowsArgumentNull(
                () => CreateProductUnderTest(command, backgroundExceptionDispatcher, initialWait),
                "backgroundExceptionDispatcher");
        }
コード例 #28
0
        public QueueListenerFactory(IStorageQueue queue,
                                    IQueueConfiguration queueConfiguration,
                                    IBackgroundExceptionDispatcher backgroundExceptionDispatcher,
                                    IContextSetter <IMessageEnqueuedWatcher> messageEnqueuedWatcherSetter,
                                    ISharedContextProvider sharedContextProvider,
                                    TextWriter log,
                                    ITriggeredFunctionInstanceFactory <IStorageQueueMessage> instanceFactory)
        {
            if (queue == null)
            {
                throw new ArgumentNullException("queue");
            }

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

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

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

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

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

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

            _queue                         = queue;
            _poisonQueue                   = CreatePoisonQueueReference(queue.ServiceClient, queue.Name);
            _queueConfiguration            = queueConfiguration;
            _backgroundExceptionDispatcher = backgroundExceptionDispatcher;
            _messageEnqueuedWatcherSetter  = messageEnqueuedWatcherSetter;
            _sharedContextProvider         = sharedContextProvider;
            _log             = log;
            _instanceFactory = instanceFactory;
        }
コード例 #29
0
        public QueueListenerFactory(IStorageQueue queue,
            IQueueConfiguration queueConfiguration,
            IBackgroundExceptionDispatcher backgroundExceptionDispatcher,
            IContextSetter<IMessageEnqueuedWatcher> messageEnqueuedWatcherSetter,
            ISharedContextProvider sharedContextProvider,
            TraceWriter trace,
            ITriggeredFunctionExecutor executor)
        {
            if (queue == null)
            {
                throw new ArgumentNullException("queue");
            }

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

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

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

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

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

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

            _queue = queue;
            _poisonQueue = CreatePoisonQueueReference(queue.ServiceClient, queue.Name);
            _queueConfiguration = queueConfiguration;
            _backgroundExceptionDispatcher = backgroundExceptionDispatcher;
            _messageEnqueuedWatcherSetter = messageEnqueuedWatcherSetter;
            _sharedContextProvider = sharedContextProvider;
            _trace = trace;
            _executor = executor;
        }
コード例 #30
0
        public QueueListenerFactory(IStorageQueue queue,
                                    IQueueConfiguration queueConfiguration,
                                    IBackgroundExceptionDispatcher backgroundExceptionDispatcher,
                                    IContextSetter <IMessageEnqueuedWatcher> messageEnqueuedWatcherSetter,
                                    ISharedContextProvider sharedContextProvider,
                                    TraceWriter trace,
                                    ITriggeredFunctionExecutor executor)
        {
            if (queue == null)
            {
                throw new ArgumentNullException("queue");
            }

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

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

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

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

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

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

            _queue                         = queue;
            _poisonQueue                   = CreatePoisonQueueReference(queue.ServiceClient, queue.Name);
            _queueConfiguration            = queueConfiguration;
            _backgroundExceptionDispatcher = backgroundExceptionDispatcher;
            _messageEnqueuedWatcherSetter  = messageEnqueuedWatcherSetter;
            _sharedContextProvider         = sharedContextProvider;
            _trace                         = trace;
            _executor                      = executor;
        }
コード例 #31
0
        public QueueListener(IStorageQueue queue,
                             IStorageQueue poisonQueue,
                             ITriggerExecutor <IStorageQueueMessage> triggerExecutor,
                             IDelayStrategy delayStrategy,
                             IBackgroundExceptionDispatcher backgroundExceptionDispatcher,
                             TraceWriter trace,
                             SharedQueueWatcher sharedWatcher,
                             IQueueConfiguration queueConfiguration)
        {
            if (trace == null)
            {
                throw new ArgumentNullException("trace");
            }

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

            if (queueConfiguration.BatchSize <= 0)
            {
                throw new ArgumentException("BatchSize must be greater than zero.");
            }

            if (queueConfiguration.MaxDequeueCount <= 0)
            {
                throw new ArgumentException("MaxDequeueCount must be greater than zero.");
            }

            _timer           = new TaskSeriesTimer(this, backgroundExceptionDispatcher, Task.Delay(0));
            _queue           = queue;
            _poisonQueue     = poisonQueue;
            _triggerExecutor = triggerExecutor;
            _delayStrategy   = delayStrategy;
            _backgroundExceptionDispatcher = backgroundExceptionDispatcher;
            _trace = trace;
            _queueConfiguration = queueConfiguration;

            if (sharedWatcher != null)
            {
                // Call Notify whenever a function adds a message to this queue.
                sharedWatcher.Register(queue.Name, this);
                _sharedWatcher = sharedWatcher;
            }

            EventHandler poisonMessageEventHandler = _sharedWatcher != null ? OnMessageAddedToPoisonQueue : (EventHandler)null;

            _queueProcessor = CreateQueueProcessor(
                _queue.SdkObject, _poisonQueue != null ? _poisonQueue.SdkObject : null,
                _trace, _queueConfiguration, poisonMessageEventHandler);
        }
コード例 #32
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;
        }
コード例 #33
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;
        }
コード例 #34
0
        public QueueListener(IStorageQueue queue,
            IStorageQueue poisonQueue,
            ITriggerExecutor<IStorageQueueMessage> triggerExecutor,
            IDelayStrategy delayStrategy,
            IBackgroundExceptionDispatcher backgroundExceptionDispatcher,
            TraceWriter trace,
            SharedQueueWatcher sharedWatcher,
            IQueueConfiguration queueConfiguration)
        {
            if (trace == null)
            {
                throw new ArgumentNullException("trace");
            }

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

            if (queueConfiguration.BatchSize <= 0)
            {
                throw new ArgumentException("BatchSize must be greater than zero.");
            }

            if (queueConfiguration.MaxDequeueCount <= 0)
            {
                throw new ArgumentException("MaxDequeueCount must be greater than zero.");
            }

            _timer = new TaskSeriesTimer(this, backgroundExceptionDispatcher, Task.Delay(0));
            _queue = queue;
            _poisonQueue = poisonQueue;
            _triggerExecutor = triggerExecutor;
            _delayStrategy = delayStrategy;
            _backgroundExceptionDispatcher = backgroundExceptionDispatcher;
            _trace = trace;
            _queueConfiguration = queueConfiguration;

            if (sharedWatcher != null)
            {
                // Call Notify whenever a function adds a message to this queue.
                sharedWatcher.Register(queue.Name, this);
                _sharedWatcher = sharedWatcher;
            }

            EventHandler poisonMessageEventHandler = _sharedWatcher != null ? OnMessageAddedToPoisonQueue : (EventHandler)null;
            _queueProcessor = CreateQueueProcessor(
                _queue.SdkObject, _poisonQueue != null ? _poisonQueue.SdkObject : null,
                _trace, _queueConfiguration, poisonMessageEventHandler);
        }
コード例 #35
0
        private static ITaskSeriesTimer StartParameterLogTimer(IRecurrentCommand updateCommand,
                                                               IBackgroundExceptionDispatcher backgroundExceptionDispatcher)
        {
            if (updateCommand == null)
            {
                return(null);
            }

            TimeSpan         initialDelay = FunctionParameterLogIntervals.InitialDelay;
            TimeSpan         refreshRate  = FunctionParameterLogIntervals.RefreshRate;
            ITaskSeriesTimer timer        = FixedDelayStrategy.CreateTimer(updateCommand, initialDelay, refreshRate,
                                                                           backgroundExceptionDispatcher);

            timer.Start();
            return(timer);
        }
        public QueueTriggerAttributeBindingProvider(INameResolver nameResolver,
            IStorageAccountProvider accountProvider,
            IQueueConfiguration queueConfiguration,
            IBackgroundExceptionDispatcher backgroundExceptionDispatcher,
            IContextSetter<IMessageEnqueuedWatcher> messageEnqueuedWatcherSetter,
            ISharedContextProvider sharedContextProvider,
            TextWriter log)
        {
            if (accountProvider == null)
            {
                throw new ArgumentNullException("accountProvider");
            }

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

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

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

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

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

            _nameResolver = nameResolver;
            _accountProvider = accountProvider;
            _queueConfiguration = queueConfiguration;
            _backgroundExceptionDispatcher = backgroundExceptionDispatcher;
            _messageEnqueuedWatcherSetter = messageEnqueuedWatcherSetter;
            _sharedContextProvider = sharedContextProvider;
            _log = log;
        }
        public QueueTriggerAttributeBindingProvider(INameResolver nameResolver,
                                                    IStorageAccountProvider accountProvider,
                                                    IQueueConfiguration queueConfiguration,
                                                    IBackgroundExceptionDispatcher backgroundExceptionDispatcher,
                                                    IContextSetter <IMessageEnqueuedWatcher> messageEnqueuedWatcherSetter,
                                                    ISharedContextProvider sharedContextProvider,
                                                    TextWriter log)
        {
            if (accountProvider == null)
            {
                throw new ArgumentNullException("accountProvider");
            }

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

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

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

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

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

            _nameResolver                  = nameResolver;
            _accountProvider               = accountProvider;
            _queueConfiguration            = queueConfiguration;
            _backgroundExceptionDispatcher = backgroundExceptionDispatcher;
            _messageEnqueuedWatcherSetter  = messageEnqueuedWatcherSetter;
            _sharedContextProvider         = sharedContextProvider;
            _log = log;
        }
コード例 #38
0
        public QueueListener(IStorageQueue queue,
                             IStorageQueue poisonQueue,
                             ITriggerExecutor <IStorageQueueMessage> triggerExecutor,
                             IDelayStrategy delayStrategy,
                             IBackgroundExceptionDispatcher backgroundExceptionDispatcher,
                             TextWriter log,
                             SharedQueueWatcher sharedWatcher,
                             int batchSize,
                             int maxDequeueCount)
        {
            if (log == null)
            {
                throw new ArgumentNullException("log");
            }

            if (batchSize <= 0)
            {
                throw new ArgumentOutOfRangeException("batchSize");
            }

            if (maxDequeueCount <= 0)
            {
                throw new ArgumentOutOfRangeException("maxDequeueCount");
            }

            _timer           = new TaskSeriesTimer(this, backgroundExceptionDispatcher, Task.Delay(0));
            _queue           = queue;
            _poisonQueue     = poisonQueue;
            _triggerExecutor = triggerExecutor;
            _delayStrategy   = delayStrategy;
            _backgroundExceptionDispatcher = backgroundExceptionDispatcher;
            _log = log;

            if (sharedWatcher != null)
            {
                // Call Notify whenever a function adds a message to this queue.
                sharedWatcher.Register(queue.Name, this);
                _sharedWatcher = sharedWatcher;
            }

            _batchSize         = batchSize;
            _newBatchThreshold = (uint)_batchSize / 2;
            _maxDequeueCount   = (uint)maxDequeueCount;
        }
コード例 #39
0
        public void Start_IfCommandExecuteAsyncsReturnsCanceledTask_DoesNotCallBackgroundExceptionDispatcher()
        {
            // Arrange
            bool executedOnce = false;

            using (EventWaitHandle executedTwiceWaitHandle = new ManualResetEvent(initialState: false))
            {
                ITaskSeriesCommand command = CreateCommand(() =>
                {
                    if (executedOnce)
                    {
                        Assert.True(executedTwiceWaitHandle.Set()); // Guard
                        return(Task.FromResult(new TaskSeriesCommandResult(Task.Delay(TimeSpan.FromDays(1)))));
                    }

                    executedOnce = true;
                    TaskCompletionSource <TaskSeriesCommandResult> taskSource =
                        new TaskCompletionSource <TaskSeriesCommandResult>();
                    taskSource.SetCanceled();
                    return(taskSource.Task);
                });

                Mock <IBackgroundExceptionDispatcher> backgroundExceptionDispatcherMock =
                    new Mock <IBackgroundExceptionDispatcher>(MockBehavior.Strict);
                int backgroundExceptionCalls = 0;
                backgroundExceptionDispatcherMock
                .Setup(d => d.Throw(It.IsAny <ExceptionDispatchInfo>()))
                .Callback(() => backgroundExceptionCalls++);
                IBackgroundExceptionDispatcher backgroundExceptionDispatcher = backgroundExceptionDispatcherMock.Object;

                using (ITaskSeriesTimer product = CreateProductUnderTest(command, backgroundExceptionDispatcher))
                {
                    // Act
                    product.Start();

                    // Assert
                    Assert.True(executedTwiceWaitHandle.WaitOne(1000)); // Guard
                    Assert.Equal(0, backgroundExceptionCalls);
                }
            }
        }
コード例 #40
0
        public void StopAsync_WhenExecuteTaskCompletesFaulted_DoesNotThrowOrFault()
        {
            // Arrange
            bool executedOnce = false;

            using (EventWaitHandle executeStarted = new ManualResetEvent(initialState: false))
                using (EventWaitHandle stopExecuteInFiveMilliseconds = new ManualResetEvent(initialState: false))
                {
                    ITaskSeriesCommand command = CreateCommand(() =>
                    {
                        if (executedOnce)
                        {
                            return(Task.FromResult(new TaskSeriesCommandResult(wait: Task.Delay(0))));
                        }

                        executedOnce = true;
                        Assert.True(executeStarted.Set()); // Guard
                        TaskCompletionSource <TaskSeriesCommandResult> taskSource =
                            new TaskCompletionSource <TaskSeriesCommandResult>();
                        taskSource.SetException(new InvalidOperationException());
                        return(taskSource.Task);
                    });

                    IBackgroundExceptionDispatcher ignoreDispatcher = CreateIgnoreBackgroundExceptionDispatcher();

                    using (ITaskSeriesTimer product = CreateProductUnderTest(command, ignoreDispatcher))
                    {
                        product.Start();
                        Assert.True(executeStarted.WaitOne(1000)); // Guard

                        CancellationToken cancellationToken = CancellationToken.None;

                        // Act
                        Task task = product.StopAsync(cancellationToken);

                        // Assert
                        Assert.NotNull(task);
                        Assert.DoesNotThrow(() => task.GetAwaiter().GetResult());
                    }
                }
        }
コード例 #41
0
        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;
        }
コード例 #42
0
        public void Start_IfCommandExecuteAsyncsReturnsFaultedTask_CallsBackgroundExceptionDispatcher()
        {
            // Arrange
            Exception expectedException = new Exception();

            ITaskSeriesCommand command = CreateCommand(() =>
            {
                TaskCompletionSource <TaskSeriesCommandResult> taskSource =
                    new TaskCompletionSource <TaskSeriesCommandResult>();
                taskSource.SetException(expectedException);
                return(taskSource.Task);
            });

            using (EventWaitHandle exceptionDispatchedWaitHandle = new ManualResetEvent(initialState: false))
            {
                Mock <IBackgroundExceptionDispatcher> backgroundExceptionDispatcherMock =
                    new Mock <IBackgroundExceptionDispatcher>(MockBehavior.Strict);
                ExceptionDispatchInfo exceptionInfo = null;
                backgroundExceptionDispatcherMock
                .Setup(d => d.Throw(It.IsAny <ExceptionDispatchInfo>()))
                .Callback <ExceptionDispatchInfo>((i) =>
                {
                    exceptionInfo = i;
                    Assert.True(exceptionDispatchedWaitHandle.Set());     // Guard
                });
                IBackgroundExceptionDispatcher backgroundExceptionDispatcher = backgroundExceptionDispatcherMock.Object;

                using (ITaskSeriesTimer product = CreateProductUnderTest(command, backgroundExceptionDispatcher))
                {
                    // Act
                    product.Start();

                    // Assert
                    Assert.True(exceptionDispatchedWaitHandle.WaitOne(1000)); // Guard
                    Assert.NotNull(exceptionInfo);
                    Assert.Same(expectedException, exceptionInfo.SourceException);
                }
            }
        }
コード例 #43
0
        public TaskSeriesTimer(ITaskSeriesCommand command, IBackgroundExceptionDispatcher backgroundExceptionDispatcher,
            Task initialWait)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

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

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

            _command = command;
            _backgroundExceptionDispatcher = backgroundExceptionDispatcher;
            _initialWait = initialWait;
            _cancellationTokenSource = new CancellationTokenSource();
        }
コード例 #44
0
        public SharedBlobListenerFactory(IStorageAccount account,
                                         IBackgroundExceptionDispatcher backgroundExceptionDispatcher,
                                         IContextSetter <IBlobWrittenWatcher> blobWrittenWatcherSetter)
        {
            if (account == null)
            {
                throw new ArgumentNullException("account");
            }

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

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

            _account = account;
            _backgroundExceptionDispatcher = backgroundExceptionDispatcher;
            _blobWrittenWatcherSetter      = blobWrittenWatcherSetter;
        }
コード例 #45
0
        private static ITaskSeriesTimer CreateUpdateMessageVisibilityTimer(IStorageQueue queue,
            IStorageQueueMessage message, TimeSpan visibilityTimeout,
            IBackgroundExceptionDispatcher backgroundExceptionDispatcher)
        {
            // Update a message's visibility when it is halfway to expiring.
            TimeSpan normalUpdateInterval = new TimeSpan(visibilityTimeout.Ticks / 2);

            IDelayStrategy speedupStrategy = new LinearSpeedupStrategy(normalUpdateInterval, TimeSpan.FromMinutes(1));
            ITaskSeriesCommand command = new UpdateQueueMessageVisibilityCommand(queue, message, visibilityTimeout, speedupStrategy);
            return new TaskSeriesTimer(command, backgroundExceptionDispatcher, Task.Delay(normalUpdateInterval));
        }
コード例 #46
0
        public BlobListenerFactory(IHostIdProvider hostIdProvider,
            IQueueConfiguration queueConfiguration,
            IBackgroundExceptionDispatcher backgroundExceptionDispatcher,
            IContextSetter<IBlobWrittenWatcher> blobWrittenWatcherSetter,
            IContextSetter<IMessageEnqueuedWatcher> messageEnqueuedWatcherSetter,
            ISharedContextProvider sharedContextProvider,
            TraceWriter trace,
            string functionId,
            IStorageAccount hostAccount,
            IStorageAccount dataAccount,
            IStorageBlobContainer container,
            IBlobPathSource input,
            ITriggeredFunctionExecutor executor,
            SingletonManager singletonManager)
        {
            if (hostIdProvider == null)
            {
                throw new ArgumentNullException("hostIdProvider");
            }

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

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

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

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

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

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

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

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

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

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

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

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

            _hostIdProvider = hostIdProvider;
            _queueConfiguration = queueConfiguration;
            _backgroundExceptionDispatcher = backgroundExceptionDispatcher;
            _blobWrittenWatcherSetter = blobWrittenWatcherSetter;
            _messageEnqueuedWatcherSetter = messageEnqueuedWatcherSetter;
            _sharedContextProvider = sharedContextProvider;
            _trace = trace;
            _functionId = functionId;
            _hostAccount = hostAccount;
            _dataAccount = dataAccount;
            _container = container;
            _input = input;
            _executor = executor;
            _singletonManager = singletonManager;
        }
コード例 #47
0
 public static ITaskSeriesTimer CreateTimer(ValueWatcherCommand command,
     IBackgroundExceptionDispatcher backgroundExceptionDispatcher)
 {
     return new TaskSeriesTimer(command, backgroundExceptionDispatcher, Task.Delay(IntialDelay));
 }
コード例 #48
0
        public BlobTriggerBinding(string parameterName,
            IArgumentBinding<IStorageBlob> argumentBinding,
            IStorageAccount account,
            IBlobPathSource path,
            IHostIdProvider hostIdProvider,
            IQueueConfiguration queueConfiguration,
            IBackgroundExceptionDispatcher backgroundExceptionDispatcher,
            IContextSetter<IBlobWrittenWatcher> blobWrittenWatcherSetter,
            IContextSetter<IMessageEnqueuedWatcher> messageEnqueuedWatcherSetter,
            ISharedContextProvider sharedContextProvider,
            TextWriter log)
        {
            if (argumentBinding == null)
            {
                throw new ArgumentNullException("argumentBinding");
            }

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

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

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

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

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

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

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

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

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

            _parameterName = parameterName;
            _argumentBinding = argumentBinding;
            _account = account;
            _client = account.CreateBlobClient();
            _accountName = BlobClient.GetAccountName(_client);
            _path = path;
            _hostIdProvider = hostIdProvider;
            _queueConfiguration = queueConfiguration;
            _backgroundExceptionDispatcher = backgroundExceptionDispatcher;
            _blobWrittenWatcherSetter = blobWrittenWatcherSetter;
            _messageEnqueuedWatcherSetter = messageEnqueuedWatcherSetter;
            _sharedContextProvider = sharedContextProvider;
            _log = log;
            _converter = CreateConverter(_client);
            _bindingDataContract = CreateBindingDataContract(path);
        }
コード例 #49
0
 private static IListener CreateHostListener(IListenerFactory allFunctionsListenerFactory,
     IRecurrentCommand heartbeatCommand, IBackgroundExceptionDispatcher backgroundExceptionDispatcher,
     CancellationToken shutdownToken)
 {
     IListener factoryListener = new ListenerFactoryListener(allFunctionsListenerFactory);
     IListener heartbeatListener = new HeartbeatListener(heartbeatCommand, backgroundExceptionDispatcher, factoryListener);
     IListener shutdownListener = new ShutdownListener(shutdownToken, heartbeatListener);
     return shutdownListener;
 }
コード例 #50
0
        public BlobTriggerBinding(ParameterInfo parameter,
            IArgumentBinding<IStorageBlob> argumentBinding,
            IStorageAccount hostAccount,
            IStorageAccount dataAccount,
            IBlobPathSource path,
            IHostIdProvider hostIdProvider,
            IQueueConfiguration queueConfiguration,
            IBackgroundExceptionDispatcher backgroundExceptionDispatcher,
            IContextSetter<IBlobWrittenWatcher> blobWrittenWatcherSetter,
            IContextSetter<IMessageEnqueuedWatcher> messageEnqueuedWatcherSetter,
            ISharedContextProvider sharedContextProvider,
            TraceWriter trace)
        {
            if (parameter == null)
            {
                throw new ArgumentNullException("parameter");
            }

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

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

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

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

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

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

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

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

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

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

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

            _parameter = parameter;
            _argumentBinding = argumentBinding;
            _hostAccount = hostAccount;
            _dataAccount = dataAccount;
            StorageClientFactoryContext context = new StorageClientFactoryContext
            {
                Parameter = parameter
            };
            _blobClient = dataAccount.CreateBlobClient(context);
            _accountName = BlobClient.GetAccountName(_blobClient);
            _path = path;
            _hostIdProvider = hostIdProvider;
            _queueConfiguration = queueConfiguration;
            _backgroundExceptionDispatcher = backgroundExceptionDispatcher;
            _blobWrittenWatcherSetter = blobWrittenWatcherSetter;
            _messageEnqueuedWatcherSetter = messageEnqueuedWatcherSetter;
            _sharedContextProvider = sharedContextProvider;
            _trace = trace;
            _converter = CreateConverter(_blobClient);
            _bindingDataContract = CreateBindingDataContract(path);
        }
コード例 #51
0
 private static TaskSeriesTimer CreateProductUnderTest(ITaskSeriesCommand command,
     IBackgroundExceptionDispatcher backgroundExceptionDispatcher)
 {
     return CreateProductUnderTest(command, backgroundExceptionDispatcher, Task.Delay(0));
 }
コード例 #52
0
 private static TaskSeriesTimer CreateProductUnderTest(ITaskSeriesCommand command,
     IBackgroundExceptionDispatcher backgroundExceptionDispatcher, Task initialWait)
 {
     return new TaskSeriesTimer(command, backgroundExceptionDispatcher, initialWait);
 }
コード例 #53
0
 private ITaskSeriesTimer CreateHeartbeatTimer(IBackgroundExceptionDispatcher backgroundExceptionDispatcher)
 {
     return LinearSpeedupStrategy.CreateTimer(_heartbeatCommand, HeartbeatIntervals.NormalSignalInterval,
         HeartbeatIntervals.MinimumSignalInterval, backgroundExceptionDispatcher);
 }
コード例 #54
0
 private static IFunctionExecutor CreateHostCallExecutor(IListenerFactory instanceQueueListenerFactory,
     IRecurrentCommand heartbeatCommand, IBackgroundExceptionDispatcher backgroundExceptionDispatcher,
     CancellationToken shutdownToken, IFunctionExecutor innerExecutor)
 {
     IFunctionExecutor heartbeatExecutor = new HeartbeatFunctionExecutor(heartbeatCommand,
         backgroundExceptionDispatcher, innerExecutor);
     IFunctionExecutor abortListenerExecutor = new AbortListenerFunctionExecutor(instanceQueueListenerFactory, heartbeatExecutor);
     IFunctionExecutor shutdownFunctionExecutor = new ShutdownFunctionExecutor(shutdownToken, abortListenerExecutor);
     return shutdownFunctionExecutor;
 }
コード例 #55
0
        private ITaskSeriesTimer CreateLeaseRenewalTimer(IStorageBlockBlob leaseBlob, string leaseId, string lockId, TimeSpan leasePeriod, 
            IBackgroundExceptionDispatcher backgroundExceptionDispatcher)
        {
            // renew the lease when it is halfway to expiring   
            TimeSpan normalUpdateInterval = new TimeSpan(leasePeriod.Ticks / 2);

            IDelayStrategy speedupStrategy = new LinearSpeedupStrategy(normalUpdateInterval, MinimumLeaseRenewalInterval);
            ITaskSeriesCommand command = new RenewLeaseCommand(leaseBlob, leaseId, lockId, speedupStrategy, _trace);
            return new TaskSeriesTimer(command, backgroundExceptionDispatcher, Task.Delay(normalUpdateInterval));
        }
コード例 #56
0
        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);
                }

                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("No functions found. Try making job classes and methods public.", 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);
            }
        }
コード例 #57
0
        public BlobListenerFactory(IHostIdProvider hostIdProvider,
            IQueueConfiguration queueConfiguration,
            IBackgroundExceptionDispatcher backgroundExceptionDispatcher,
            IContextSetter<IBlobWrittenWatcher> blobWrittenWatcherSetter,
            IContextSetter<IMessageEnqueuedWatcher> messageEnqueuedWatcherSetter,
            ISharedContextProvider sharedContextProvider,
            TextWriter log,
            string functionId,
            IStorageAccount account,
            IStorageBlobContainer container,
            IBlobPathSource input,
            ITriggeredFunctionExecutor<IStorageBlob> executor)
        {
            if (hostIdProvider == null)
            {
                throw new ArgumentNullException("hostIdProvider");
            }

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

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

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

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

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

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

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

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

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

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

            _hostIdProvider = hostIdProvider;
            _queueConfiguration = queueConfiguration;
            _backgroundExceptionDispatcher = backgroundExceptionDispatcher;
            _blobWrittenWatcherSetter = blobWrittenWatcherSetter;
            _messageEnqueuedWatcherSetter = messageEnqueuedWatcherSetter;
            _sharedContextProvider = sharedContextProvider;
            _log = log;
            _functionId = functionId;
            _account = account;
            _container = container;
            _input = input;
            _executor = executor;
        }