/// <inheritdoc/> public virtual async Task <V1WorkflowInstance> StartSubflowAsync(V1CreateWorkflowInstanceCommand command, CancellationToken cancellationToken = default) { if (command == null) { throw new ArgumentNullException(nameof(command)); } return(await this.Mediator.ExecuteAndUnwrapAsync(this.Mapper.Map <Application.Commands.WorkflowInstances.V1CreateWorkflowInstanceCommand>(command), cancellationToken)); }
/// <inheritdoc/> public virtual async Task <V1WorkflowInstance> CreateWorkflowInstanceAsync(V1CreateWorkflowInstanceCommand command, CancellationToken cancellationToken = default) { var result = await this.Adapter.CreateWorkflowInstanceAsync(command, cancellationToken); if (!result.Succeeded) { throw new SynapseApiException(result); } return(result.Data !); }
/// <inheritdoc/> public virtual async Task <V1WorkflowInstance> StartSubflowAsync(V1CreateWorkflowInstanceCommand command, CancellationToken cancellationToken = default) { var result = await this.RuntimeApi.StartSubflowAsync(command, cancellationToken); if (!result.Succeeded) { throw new OperationResultException(new OperationResult(result.Code, result.Errors?.Select(e => new Neuroglia.Error(e.Code, e.Message))?.ToArray())); } return(result.Data !); }
/// <inheritdoc/> public virtual async Task <V1WorkflowInstance> CreateWorkflowInstanceAsync(V1CreateWorkflowInstanceCommand command, CancellationToken cancellationToken = default) { var requestUri = "/api/v1/workflow-instances"; using var request = this.CreateRequest(HttpMethod.Post, requestUri); var json = await this.Serializer.SerializeAsync(command, cancellationToken); request.Content = new StringContent(json, Encoding.UTF8, MediaTypeNames.Application.Json); using var response = await this.HttpClient.SendAsync(request, cancellationToken); json = await response.Content?.ReadAsStringAsync(cancellationToken) !; if (!response.IsSuccessStatusCode) { this.Logger.LogError("An error occured while creating a new workflow instance: {details}", json); } response.EnsureSuccessStatusCode(); return(await this.Serializer.DeserializeAsync <V1WorkflowInstance>(json, cancellationToken)); }
/// <inheritdoc/> public virtual async Task <GrpcApiResult <V1WorkflowInstance> > StartSubflowAsync(V1CreateWorkflowInstanceCommand command, CallContext context = default) { return(GrpcApiResult.CreateFor(await this.Mediator.ExecuteAsync(this.Mapper.Map <Application.Commands.WorkflowInstances.V1CreateWorkflowInstanceCommand>(command), context.CancellationToken))); }