// This snapshot won't contain full normal data for Function.FullName, Function.ShortName and Function.Parameters. // (All we know is an unavailable function ID; which function location method info to use is a mystery.) private static FunctionCompletedMessage CreateFailedMessage(CallAndOverrideMessage message) { DateTimeOffset startAndEndTime = DateTimeOffset.UtcNow; Exception exception = new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "No function '{0}' currently exists.", message.FunctionId)); // In theory, we could also set HostId, HostInstanceId and WebJobRunId; we'd just have to expose that data // directly to this Worker class. return(new FunctionCompletedMessage { FunctionInstanceId = message.Id, Function = new FunctionDescriptor { Id = message.FunctionId }, Arguments = message.Arguments, ParentId = message.ParentId, Reason = message.Reason, StartTime = startAndEndTime, EndTime = startAndEndTime, Failure = new FunctionFailure { Exception = exception, ExceptionType = exception.GetType().FullName, ExceptionDetails = exception.Message } }); }
private IFunctionInstance CreateFunctionInstance(CallAndOverrideMessage message) { IFunctionDefinition function = _functionLookup.Lookup(message.FunctionId); if (function == null) { return(null); } IDictionary <string, object> objectParameters = new Dictionary <string, object>(); if (message.Arguments != null) { foreach (KeyValuePair <string, string> item in message.Arguments) { objectParameters.Add(item.Key, item.Value); } } var context = new FunctionInstanceFactoryContext { Id = message.Id, ParentId = message.ParentId, ExecutionReason = message.Reason, Parameters = objectParameters }; return(function.InstanceFactory.Create(context)); }
public async Task <FunctionResult> ExecuteAsync(IStorageQueueMessage value, CancellationToken cancellationToken) { HostMessage model = JsonConvert.DeserializeObject <HostMessage>(value.AsString, JsonSerialization.Settings); if (model == null) { throw new InvalidOperationException("Invalid invocation message."); } CallAndOverrideMessage callAndOverrideModel = model as CallAndOverrideMessage; if (callAndOverrideModel != null) { await ProcessCallAndOverrideMessage(callAndOverrideModel, cancellationToken); return(new FunctionResult(true)); } AbortHostInstanceMessage abortModel = model as AbortHostInstanceMessage; if (abortModel != null) { ProcessAbortHostInstanceMessage(); return(new FunctionResult(true)); } string error = String.Format(CultureInfo.InvariantCulture, "Unsupported invocation type '{0}'.", model.Type); throw new NotSupportedException(error); }
public Guid TriggerAndOverride(string queueName, FunctionSnapshot function, IDictionary<string, string> arguments, Guid? parentId, ExecutionReason reason) { if (function == null) { throw new ArgumentNullException("function"); } Guid id = Guid.NewGuid(); CallAndOverrideMessage message = new CallAndOverrideMessage { Id = id, FunctionId = function.HostFunctionId, Arguments = arguments, ParentId = parentId, Reason = reason }; string functionId = new FunctionIdentifier(function.QueueName, function.HostFunctionId).ToString(); FunctionInstanceSnapshot snapshot = CreateSnapshot(id, arguments, parentId, DateTimeOffset.UtcNow, functionId, function.FullName, function.ShortName); _logger.LogFunctionQueued(snapshot); _sender.Enqueue(queueName, message); return id; }
public Guid TriggerAndOverride(string queueName, FunctionSnapshot function, IDictionary <string, string> arguments, Guid?parentId, ExecutionReason reason) { if (function == null) { throw new ArgumentNullException("function"); } Guid id = Guid.NewGuid(); CallAndOverrideMessage message = new CallAndOverrideMessage { Id = id, FunctionId = function.HostFunctionId, Arguments = arguments, ParentId = parentId, Reason = reason }; string functionId = new FunctionIdentifier(function.QueueName, function.HostFunctionId).ToString(); FunctionInstanceSnapshot snapshot = CreateSnapshot(id, arguments, parentId, DateTimeOffset.UtcNow, functionId, function.FullName, function.ShortName); _logger.LogFunctionQueued(snapshot); _sender.Enqueue(queueName, message); return(id); }
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 void JsonConvertDerivedType_Roundtrips() { // Arrange CallAndOverrideMessage expectedMessage = new CallAndOverrideMessage { Id = Guid.NewGuid() }; // Act HostMessage message = JsonConvert.DeserializeObject<HostMessage>( JsonConvert.SerializeObject(expectedMessage)); // Assert Assert.NotNull(message); Assert.IsType<CallAndOverrideMessage>(message); CallAndOverrideMessage typedMessage = (CallAndOverrideMessage)message; Assert.Equal(expectedMessage.Id, typedMessage.Id); }
public void JsonConvertDerivedType_Roundtrips() { // Arrange CallAndOverrideMessage expectedMessage = new CallAndOverrideMessage { Id = Guid.NewGuid() }; // Act HostMessage message = JsonConvert.DeserializeObject <HostMessage>( JsonConvert.SerializeObject(expectedMessage)); // Assert Assert.NotNull(message); Assert.IsType <CallAndOverrideMessage>(message); CallAndOverrideMessage typedMessage = (CallAndOverrideMessage)message; Assert.Equal(expectedMessage.Id, typedMessage.Id); }