public async Task DispatchAsync(ExecuteWorkflowInstanceRequest request, CancellationToken cancellationToken = default) { var workflowInstance = await _workflowInstanceStore.FindByIdAsync(request.WorkflowInstanceId, cancellationToken); if (workflowInstance == null) { _logger.LogWarning("Cannot dispatch a workflow instance ID that does not exist"); return; } var workflowBlueprint = await _workflowRegistry.FindAsync(workflowInstance.DefinitionId, VersionOptions.SpecificVersion(workflowInstance.Version), workflowInstance.TenantId, cancellationToken); if (workflowBlueprint == null) { _logger.LogWarning("Workflow instance {WorkflowInstanceId} references workflow blueprint {WorkflowDefinitionId} with version {Version}, but could not be found", workflowInstance.Id, workflowInstance.DefinitionId, workflowInstance.Version); return; } var channel = _workflowChannelOptions.GetChannelOrDefault(workflowBlueprint.Channel); var queue = ServiceBusOptions.FormatChannelQueueName <ExecuteWorkflowInstanceRequest>(channel); await _commandSender.SendAsync(request, queue, cancellationToken : cancellationToken); }
public async Task DispatchAsync(ExecuteWorkflowDefinitionRequest request, CancellationToken cancellationToken = default) { var workflowBlueprint = await _workflowRegistry.FindAsync(request.WorkflowDefinitionId, VersionOptions.Published, request.TenantId, cancellationToken); if (workflowBlueprint == null) { _logger.LogWarning("No published version found for workflow blueprint {WorkflowDefinitionId}", request.WorkflowDefinitionId); return; } var channel = _workflowChannelOptions.GetChannelOrDefault(workflowBlueprint.Channel); var queue = ServiceBusOptions.FormatChannelQueueName <ExecuteWorkflowDefinitionRequest>(channel); EnqueueJob <WorkflowDefinitionJob>(x => x.ExecuteAsync(request, CancellationToken.None), queue); }
public async Task <StartableWorkflow?> FindStartableWorkflowAsync( string workflowDefinitionId, string?activityId, string?correlationId = default, string?contextId = default, string?tenantId = default, CancellationToken cancellationToken = default) { var workflowBlueprint = await _workflowRegistry.FindAsync(workflowDefinitionId, VersionOptions.Published, tenantId, cancellationToken); if (workflowBlueprint == null || workflowBlueprint.IsDisabled) { return(null); } return(await FindStartableWorkflowAsync(workflowBlueprint, activityId, correlationId, contextId, tenantId, cancellationToken)); }
public async Task <string> Get() { var workflow = await workflowRegistry.FindAsync(f => f.Name == "TestWorkFlow"); var instance = await workflowFactory.InstantiateAsync(workflow); await workflowInstanceStore.AddAsync(instance); await workflowInvoker.RunWorkflowAsync(workflow, instance); await workflowInstanceDispatcher.DispatchAsync(new ExecuteWorkflowInstanceRequest(instance.Id, "activity-start")); return(instance.Id); }
public async Task <RunWorkflowResult> ResumeWorkflowAsync(WorkflowInstance workflowInstance, string?activityId = default, CancellationToken cancellationToken = default) { var workflowBlueprint = await _workflowRegistry.FindAsync( workflowInstance.DefinitionId, VersionOptions.SpecificVersion(workflowInstance.Version), workflowInstance.TenantId, cancellationToken); if (workflowBlueprint == null) { throw new WorkflowException($"Workflow instance {workflowInstance.Id} references workflow definition {workflowInstance.DefinitionId} version {workflowInstance.Version}, but no such workflow definition was found."); } if (workflowBlueprint.IsDisabled) { return(new RunWorkflowResult(workflowInstance, activityId, null, false)); } return(await _workflowRunner.RunWorkflowAsync(workflowBlueprint, workflowInstance, activityId, cancellationToken)); }
public async Task <RunWorkflowResult?> FindAndRestartTestWorkflowAsync( string workflowDefinitionId, string activityId, int version, string signalRConnectionId, string lastWorkflowInstanceId, string?tenantId = default, CancellationToken cancellationToken = default) { var workflowBlueprint = await _workflowRegistry.FindAsync(workflowDefinitionId, VersionOptions.SpecificVersion(version), tenantId, cancellationToken); if (workflowBlueprint == null) { return(null); } var lastWorkflowInstance = await _workflowInstanceStore.FindAsync(new EntityIdSpecification <WorkflowInstance>(lastWorkflowInstanceId), cancellationToken); if (lastWorkflowInstance == null) { return(null); } var startActivity = workflowBlueprint.Activities.First(x => x.Id == activityId); var startableWorkflowDefinition = new StartableWorkflowDefinition(workflowBlueprint, startActivity.Id); var workflow = await InstantiateStartableWorkflow(startableWorkflowDefinition, cancellationToken); var previousActivityData = GetActivityDataFromLastWorkflowInstance(lastWorkflowInstance, workflowBlueprint, activityId); MergeActivityDataIntoInstance(workflow.WorkflowInstance, previousActivityData); SetMetadata(workflow.WorkflowInstance, signalRConnectionId); //if previousActivityOutput has any items, then the first one is from activity closest to the starting one var previousActivityOutput = previousActivityData.Count == 0 ? null : previousActivityData.First().Value?.GetItem("Output"); return(await ExecuteStartableWorkflowAsync(workflow, new WorkflowInput(previousActivityOutput), cancellationToken)); }
public async Task Handle(ExecuteWorkflowDefinitionRequest message) { var workflowDefinitionId = message.WorkflowDefinitionId; var tenantId = message.TenantId; var workflowBlueprint = await _workflowRegistry.FindAsync(workflowDefinitionId, VersionOptions.Published, tenantId); if (workflowBlueprint == null) { _logger.LogWarning("Could not find workflow with ID {WorkflowDefinitionId}", workflowDefinitionId); return; } var startableWorkflow = await _workflowLaunchpad.FindStartableWorkflowAsync(workflowBlueprint, message.ActivityId, message.CorrelationId, message.ContextId, tenantId); if (startableWorkflow == null) { _logger.LogDebug("Could not start workflow with ID {WorkflowDefinitionId}", workflowDefinitionId); return; } await _workflowLaunchpad.ExecuteStartableWorkflowAsync(startableWorkflow, message.Input); }
public async Task <IWorkflowBlueprint?> FindAsync(string definitionId, VersionOptions versionOptions, string?tenantId = default, CancellationToken cancellationToken = default) { var cacheKey = $"{RootKey}:definition:id:{definitionId}:{versionOptions}:{tenantId}"; return(await FindInternalAsync(cacheKey, () => _workflowRegistry.FindAsync(definitionId, versionOptions, tenantId, cancellationToken), cancellationToken)); }
private async Task <IWorkflowBlueprint?> GetWorkflowBlueprintAsync(WorkflowInstance workflowInstance, CancellationToken cancellationToken) => await _workflowRegistry.FindAsync(workflowInstance.DefinitionId, VersionOptions.SpecificVersion(workflowInstance.Version), workflowInstance.TenantId, cancellationToken);
public static Task <IWorkflowBlueprint?> GetWorkflowAsync <T>( this IWorkflowRegistry workflowRegistry, string?tenantId, CancellationToken cancellationToken = default) => workflowRegistry.FindAsync(typeof(T).Name, VersionOptions.Latest, tenantId, cancellationToken);
public async Task <ActionResult <WorkflowBlueprintModel> > Handle(string id, VersionOptions?versionOptions = default, CancellationToken cancellationToken = default) { versionOptions ??= VersionOptions.Latest; var workflowBlueprint = await _workflowRegistry.FindAsync(id, versionOptions.Value, default, cancellationToken);