private async Task <StartableWorkflow> InstantiateStartableWorkflow(StartableWorkflowDefinition startableWorkflowDefinition, CancellationToken cancellationToken) { var workflowInstance = await _workflowFactory.InstantiateAsync( startableWorkflowDefinition.WorkflowBlueprint, startableWorkflowDefinition.CorrelationId, startableWorkflowDefinition.ContextId, cancellationToken : cancellationToken); await _workflowInstanceStore.SaveAsync(workflowInstance, cancellationToken); return(new StartableWorkflow(startableWorkflowDefinition.WorkflowBlueprint, workflowInstance, startableWorkflowDefinition.ActivityId)); }
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)); }