Пример #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);
        }
Пример #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);
            await _commandSender.SendAsync(request, queue, default, cancellationToken);
Пример #3
0
        public static BackgroundJobServerOptions ConfigureForElsaDispatchers(this BackgroundJobServerOptions options, IServiceProvider serviceProvider)
        {
            var queues = options.Queues.ToHashSet();

            // Add default worker queues.
            queues.AddRange(new[] { QueueNames.CorrelatedWorkflows });

            // Add queue variations based on workflow channels, if any.
            var elsaOptions = serviceProvider.GetRequiredService <ElsaOptions>();
            var channels    = elsaOptions.WorkflowChannelOptions.Channels;

            foreach (var channel in channels)
            {
                queues.Add(ServiceBusOptions.FormatChannelQueueName <ExecuteWorkflowDefinitionRequest>(channel));
                queues.Add(ServiceBusOptions.FormatChannelQueueName <ExecuteWorkflowInstanceRequest>(channel));
            }

            options.Queues = queues.ToArray();

            return(options);
        }
Пример #4
0
        public CreateSubscriptions(IServiceBusFactory serviceBusFactory, ElsaOptions elsaOptions, IContainerNameAccessor containerNameAccessor, IDistributedLockProvider distributedLockProvider)
        {
            _serviceBusFactory       = serviceBusFactory;
            _elsaOptions             = elsaOptions;
            _containerNameAccessor   = containerNameAccessor;
            _distributedLockProvider = distributedLockProvider;
            _competingMessageTypes   = elsaOptions.CompetingMessageTypes.ToList();
            _pubSubMessageTypes      = elsaOptions.PubSubMessageTypes;

            var workflowChannelOptions = elsaOptions.WorkflowChannelOptions;
            var workflowChannels       = workflowChannelOptions.Channels.ToList();

            // For each workflow channel, register a competing message type for workflow definition and workflow instance consumers.
            foreach (var workflowChannel in workflowChannels)
            {
                _competingMessageTypes.Add(new MessageTypeConfig(typeof(ExecuteWorkflowDefinitionRequest), ServiceBusOptions.FormatChannelQueueName("ExecuteWorkflow", workflowChannel)));
                _competingMessageTypes.Add(new MessageTypeConfig(typeof(ExecuteWorkflowInstanceRequest), ServiceBusOptions.FormatChannelQueueName("ExecuteWorkflow", workflowChannel)));
            }
        }