From e316ca6c8042e3c4e65b591dbaa0fc3006b2a568 Mon Sep 17 00:00:00 2001 From: Rafael Carnucci Date: Mon, 26 Jul 2021 08:00:42 +0200 Subject: [PATCH] Added TenantId in IStartsWorkflow.StartWorkflowAsync and IWorkflowFactory.InstantiateAsync --- .../Services/Workflows/IStartsWorkflow.cs | 3 ++- .../Services/Workflows/IWorkflowFactory.cs | 1 + .../Activities/Workflows/RunWorkflow/RunWorkflow.cs | 4 ++-- src/core/Elsa.Core/Services/Workflows/WorkflowFactory.cs | 3 ++- src/core/Elsa.Core/Services/Workflows/WorkflowLaunchpad.cs | 4 ++-- src/core/Elsa.Core/Services/Workflows/WorkflowStarter.cs | 7 ++++--- ...flowExecutionContextForWorkflowBlueprintFactoryTests.cs | 2 +- 7 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/core/Elsa.Abstractions/Services/Workflows/IStartsWorkflow.cs b/src/core/Elsa.Abstractions/Services/Workflows/IStartsWorkflow.cs index c9f8bb241..4a889ad88 100644 --- a/src/core/Elsa.Abstractions/Services/Workflows/IStartsWorkflow.cs +++ b/src/core/Elsa.Abstractions/Services/Workflows/IStartsWorkflow.cs @@ -1,4 +1,4 @@ -using System.Threading; +using System.Threading; using System.Threading.Tasks; using Elsa.Models; using Elsa.Services.Models; @@ -13,6 +13,7 @@ namespace Elsa.Services WorkflowInput? input = default, string? correlationId = default, string? contextId = default, + string? tenantId = default, CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/core/Elsa.Abstractions/Services/Workflows/IWorkflowFactory.cs b/src/core/Elsa.Abstractions/Services/Workflows/IWorkflowFactory.cs index 292f993bb..3211ce516 100644 --- a/src/core/Elsa.Abstractions/Services/Workflows/IWorkflowFactory.cs +++ b/src/core/Elsa.Abstractions/Services/Workflows/IWorkflowFactory.cs @@ -11,6 +11,7 @@ namespace Elsa.Services IWorkflowBlueprint workflowBlueprint, string? correlationId = default, string? contextId = default, + string? tenantId = default, CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/core/Elsa.Core/Activities/Workflows/RunWorkflow/RunWorkflow.cs b/src/core/Elsa.Core/Activities/Workflows/RunWorkflow/RunWorkflow.cs index b05f57aeb..eab22dc03 100644 --- a/src/core/Elsa.Core/Activities/Workflows/RunWorkflow/RunWorkflow.cs +++ b/src/core/Elsa.Core/Activities/Workflows/RunWorkflow/RunWorkflow.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading; @@ -101,7 +101,7 @@ namespace Elsa.Activities.Workflows if (workflowBlueprint == null || workflowBlueprint.Id == context.WorkflowInstance.DefinitionId) return Outcome("Not Found"); - var result = await _startsWorkflow.StartWorkflowAsync(workflowBlueprint!, TenantId, new WorkflowInput(Input), CorrelationId, ContextId, cancellationToken); + var result = await _startsWorkflow.StartWorkflowAsync(workflowBlueprint!, TenantId, new WorkflowInput(Input), CorrelationId, ContextId, cancellationToken: cancellationToken); var workflowInstance = result.WorkflowInstance!; var workflowStatus = result.WorkflowInstance!.WorkflowStatus; diff --git a/src/core/Elsa.Core/Services/Workflows/WorkflowFactory.cs b/src/core/Elsa.Core/Services/Workflows/WorkflowFactory.cs index afae48971..891c0e2d5 100644 --- a/src/core/Elsa.Core/Services/Workflows/WorkflowFactory.cs +++ b/src/core/Elsa.Core/Services/Workflows/WorkflowFactory.cs @@ -22,13 +22,14 @@ namespace Elsa.Services.Workflows IWorkflowBlueprint workflowBlueprint, string? correlationId = default, string? contextId = default, + string? tenantId = default, CancellationToken cancellationToken = default) { var workflowInstance = new WorkflowInstance { Id = _idGenerator.Generate(), DefinitionId = workflowBlueprint.Id, - TenantId = workflowBlueprint.TenantId, + TenantId = tenantId ?? workflowBlueprint.TenantId, Version = workflowBlueprint.Version, WorkflowStatus = WorkflowStatus.Idle, CorrelationId = correlationId ?? Guid.NewGuid().ToString("N"), diff --git a/src/core/Elsa.Core/Services/Workflows/WorkflowLaunchpad.cs b/src/core/Elsa.Core/Services/Workflows/WorkflowLaunchpad.cs index 9b83f95e8..bd2fb55b6 100644 --- a/src/core/Elsa.Core/Services/Workflows/WorkflowLaunchpad.cs +++ b/src/core/Elsa.Core/Services/Workflows/WorkflowLaunchpad.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading; @@ -270,7 +270,7 @@ namespace Elsa.Services.Workflows workflowBlueprint, correlationId, contextId, - cancellationToken); + cancellationToken: cancellationToken); await _workflowInstanceStore.SaveAsync(workflowInstance, cancellationToken); return new StartableWorkflow(workflowBlueprint, workflowInstance, startActivityId); diff --git a/src/core/Elsa.Core/Services/Workflows/WorkflowStarter.cs b/src/core/Elsa.Core/Services/Workflows/WorkflowStarter.cs index 8840030ee..c16d1e925 100644 --- a/src/core/Elsa.Core/Services/Workflows/WorkflowStarter.cs +++ b/src/core/Elsa.Core/Services/Workflows/WorkflowStarter.cs @@ -71,13 +71,14 @@ namespace Elsa.Services.Workflows WorkflowInput? input = default, string? correlationId = default, string? contextId = default, + string? tenantId = default, CancellationToken cancellationToken = default) { var workflowInstance = await _workflowFactory.InstantiateAsync( workflowBlueprint, correlationId, contextId, - cancellationToken); + cancellationToken: cancellationToken); await _workflowInstanceStore.SaveAsync(workflowInstance, cancellationToken); return await _workflowRunner.RunWorkflowAsync(workflowBlueprint, workflowInstance, activityId, input, cancellationToken); @@ -91,7 +92,7 @@ namespace Elsa.Services.Workflows CancellationToken cancellationToken = default) where T : IWorkflow { var workflowBlueprint = _workflowBuilderFactory().Build(); - return await StartWorkflowAsync(workflowBlueprint, activityId, input, correlationId, contextId, cancellationToken); + return await StartWorkflowAsync(workflowBlueprint, activityId, input, correlationId, contextId, cancellationToken: cancellationToken); } public async Task BuildAndStartWorkflowAsync( @@ -103,7 +104,7 @@ namespace Elsa.Services.Workflows CancellationToken cancellationToken = default) { var workflowBlueprint = _workflowBuilderFactory().Build(workflow); - return await StartWorkflowAsync(workflowBlueprint, activityId, input, correlationId, contextId, cancellationToken); + return await StartWorkflowAsync(workflowBlueprint, activityId, input, correlationId, contextId, cancellationToken: cancellationToken); } } } \ No newline at end of file diff --git a/test/unit/Elsa.UnitTests/Services/WorkflowExecutionContextForWorkflowBlueprintFactoryTests.cs b/test/unit/Elsa.UnitTests/Services/WorkflowExecutionContextForWorkflowBlueprintFactoryTests.cs index 902cb70f7..9be189cf7 100644 --- a/test/unit/Elsa.UnitTests/Services/WorkflowExecutionContextForWorkflowBlueprintFactoryTests.cs +++ b/test/unit/Elsa.UnitTests/Services/WorkflowExecutionContextForWorkflowBlueprintFactoryTests.cs @@ -20,7 +20,7 @@ namespace Elsa.Services { var sut = new WorkflowExecutionContextForWorkflowBlueprintFactory(serviceProvider, workflowFactory); Mock.Get(workflowFactory) - .Setup(x => x.InstantiateAsync(workflowBlueprint, default, default, default)) + .Setup(x => x.InstantiateAsync(workflowBlueprint, default, default, default, default)) .Returns(() => Task.FromResult(instance)); var result = await sut.CreateWorkflowExecutionContextAsync(workflowBlueprint);