Exemplo n.º 1
0
        public async Task <FunctionResult> TryExecuteAsync(TriggeredFunctionData input, CancellationToken cancellationToken)
        {
            var context = new FunctionInstanceFactoryContext <TTriggerValue>()
            {
                TriggerValue   = (TTriggerValue)input.TriggerValue,
                ParentId       = input.ParentId,
                TriggerDetails = input.TriggerDetails
            };

            if (input.InvokeHandler != null)
            {
                context.InvokeHandler = async next =>
                {
                    await input.InvokeHandler(next);

                    // NOTE: The InvokeHandler code path currently does not support flowing the return
                    // value back to the trigger.
                    return(null);
                };
            }

            IFunctionInstance instance  = _instanceFactory.Create(context);
            IDelayedException exception = await _executor.TryExecuteAsync(instance, cancellationToken);

            FunctionResult result = exception != null ?
                                    new FunctionResult(exception.Exception)
                : new FunctionResult(true);

            return(result);
        }
        public async Task <bool> ExecuteAsync(BrokeredMessage value, CancellationToken cancellationToken)
        {
            Guid?parentId = ServiceBusCausalityHelper.GetOwner(value);
            IFunctionInstance instance  = _instanceFactory.Create(value, parentId);
            IDelayedException exception = await _innerExecutor.TryExecuteAsync(instance, cancellationToken);

            return(exception == null);
        }
Exemplo n.º 3
0
 public async Task <IDelayedException> TryExecuteAsync(IFunctionInstance instance, CancellationToken cancellationToken)
 {
     using (CancellationTokenSource callCancellationSource = CancellationTokenSource.CreateLinkedTokenSource(
                _shutdownToken, cancellationToken))
     {
         return(await _innerExecutor.TryExecuteAsync(instance, callCancellationSource.Token));
     }
 }
Exemplo n.º 4
0
        public async Task <bool> ExecuteAsync(IStorageQueueMessage value, CancellationToken cancellationToken)
        {
            Guid?parentId = QueueCausalityManager.GetOwner(value);
            IFunctionInstance instance  = _instanceFactory.Create(value, parentId);
            IDelayedException exception = await _innerExecutor.TryExecuteAsync(instance, cancellationToken);

            return(exception == null);
        }
Exemplo n.º 5
0
        public async Task <FunctionResult> TryExecuteAsync(TriggeredFunctionData input, CancellationToken cancellationToken)
        {
            IFunctionInstance instance  = _instanceFactory.Create((TTriggerValue)input.TriggerValue, input.ParentId);
            IDelayedException exception = await _executor.TryExecuteAsync(instance, cancellationToken);

            FunctionResult result = exception != null ?
                                    new FunctionResult(exception.Exception)
                : new FunctionResult(true);

            return(result);
        }
Exemplo n.º 6
0
        private async Task ProcessCallAndOverrideMessage(CallAndOverrideMessage message, CancellationToken cancellationToken)
        {
            IFunctionInstance instance = CreateFunctionInstance(message);

            if (instance != null)
            {
                await _innerExecutor.TryExecuteAsync(instance, cancellationToken);
            }
            else
            {
                // Log that the function failed.
                FunctionCompletedMessage failedMessage = CreateFailedMessage(message);
                await _functionInstanceLogger.LogFunctionCompletedAsync(failedMessage, cancellationToken);
            }
        }
        public async Task <IDelayedException> TryExecuteAsync(IFunctionInstance instance, CancellationToken cancellationToken)
        {
            IDelayedException result;

            using (IListener listener = await _abortListenerFactory.CreateAsync(cancellationToken))
            {
                await listener.StartAsync(cancellationToken);

                result = await _innerExecutor.TryExecuteAsync(instance, cancellationToken);

                await listener.StopAsync(cancellationToken);
            }

            return(result);
        }
Exemplo n.º 8
0
        public async Task <IDelayedException> TryExecuteAsync(IFunctionInstance instance, CancellationToken cancellationToken)
        {
            IDelayedException result;

            using (ITaskSeriesTimer timer = CreateHeartbeatTimer(_exceptionHandler))
            {
                await _heartbeatCommand.TryExecuteAsync(cancellationToken);

                timer.Start();

                result = await _innerExecutor.TryExecuteAsync(instance, cancellationToken);

                await timer.StopAsync(cancellationToken);
            }

            return(result);
        }
        public async Task <bool> ExecuteAsync(IStorageQueueMessage value, CancellationToken cancellationToken)
        {
            BlobTriggerMessage message = JsonConvert.DeserializeObject <BlobTriggerMessage>(value.AsString,
                                                                                            JsonSerialization.Settings);

            if (message == null)
            {
                throw new InvalidOperationException("Invalid blob trigger message.");
            }

            string functionId = message.FunctionId;

            if (functionId == null)
            {
                throw new InvalidOperationException("Invalid function ID.");
            }

            // Ensure that the function ID is still valid. Otherwise, ignore this message.
            ITriggeredFunctionInstanceFactory <IStorageBlob> instanceFactory;

            if (!_registrations.TryGetValue(functionId, out instanceFactory))
            {
                return(true);
            }

            IStorageBlobContainer container = _client.GetContainerReference(message.ContainerName);
            string blobName = message.BlobName;

            IStorageBlob blob;

            switch (message.BlobType)
            {
            case StorageBlobType.PageBlob:
                blob = container.GetPageBlobReference(blobName);
                break;

            case StorageBlobType.BlockBlob:
            default:
                blob = container.GetBlockBlobReference(blobName);
                break;
            }

            // Ensure the blob still exists with the same ETag.
            string possibleETag = await _eTagReader.GetETagAsync(blob, cancellationToken);

            if (possibleETag == null)
            {
                // If the blob no longer exists, just ignore this message.
                return(true);
            }

            // If the blob still exists but the ETag is different, delete the message but do a fast path notification.
            if (!String.Equals(message.ETag, possibleETag, StringComparison.Ordinal))
            {
                _blobWrittenWatcher.Notify(blob);
                return(true);
            }

            //// If the blob still exists and its ETag is still valid, execute.
            //// Note: it's possible the blob could change/be deleted between now and when the function executes.
            Guid?parentId = await _causalityReader.GetWriterAsync(blob, cancellationToken);

            IFunctionInstance instance  = instanceFactory.Create(blob, parentId);
            IDelayedException exception = await _innerExecutor.TryExecuteAsync(instance, cancellationToken);

            return(exception == null);
        }