Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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));
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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));
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 8
0
        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));
        }
Ejemplo n.º 9
0
 private async Task <IWorkflowBlueprint?> GetWorkflowBlueprintAsync(WorkflowInstance workflowInstance, CancellationToken cancellationToken) =>
 await _workflowRegistry.FindAsync(workflowInstance.DefinitionId, VersionOptions.SpecificVersion(workflowInstance.Version), workflowInstance.TenantId, cancellationToken);
Ejemplo n.º 10
0
 public static Task <IWorkflowBlueprint?> GetWorkflowAsync <T>(
     this IWorkflowRegistry workflowRegistry,
     string?tenantId,
     CancellationToken cancellationToken = default) =>
 workflowRegistry.FindAsync(typeof(T).Name, VersionOptions.Latest, tenantId, cancellationToken);
Ejemplo n.º 11
0
 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);