Added TenantId in IStartsWorkflow.StartWorkflowAsync and IWorkflowFactory.InstantiateAsync

This commit is contained in:
Rafael Carnucci 2021-07-26 08:00:42 +02:00 committed by Sipke Schoorstra
parent 19caa5e0ac
commit e316ca6c80
7 changed files with 14 additions and 10 deletions

View file

@ -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);
}
}

View file

@ -11,6 +11,7 @@ namespace Elsa.Services
IWorkflowBlueprint workflowBlueprint,
string? correlationId = default,
string? contextId = default,
string? tenantId = default,
CancellationToken cancellationToken = default);
}
}

View file

@ -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;

View file

@ -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"),

View file

@ -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);

View file

@ -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<T>();
return await StartWorkflowAsync(workflowBlueprint, activityId, input, correlationId, contextId, cancellationToken);
return await StartWorkflowAsync(workflowBlueprint, activityId, input, correlationId, contextId, cancellationToken: cancellationToken);
}
public async Task<RunWorkflowResult> 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);
}
}
}

View file

@ -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);