< Summary

Information
Class: Elsa.Alterations.Services.DefaultAlterationPlanScheduler
Assembly: Elsa.Alterations
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Alterations/Services/DefaultAlterationPlanScheduler.cs
Line coverage
26%
Covered lines: 6
Uncovered lines: 17
Coverable lines: 23
Total lines: 59
Line coverage: 26%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
SubmitAsync()0%2040%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Alterations/Services/DefaultAlterationPlanScheduler.cs

#LineLine coverage
 1using Elsa.Alterations.Core.Contracts;
 2using Elsa.Alterations.Core.Models;
 3using Elsa.Alterations.Workflows;
 4using Elsa.Common;
 5using Elsa.Common.Models;
 6using Elsa.Workflows;
 7using Elsa.Workflows.Management;
 8using Elsa.Workflows.Runtime;
 9using Elsa.Workflows.Runtime.Contracts;
 10using Elsa.Workflows.Runtime.Requests;
 11
 12namespace Elsa.Alterations.Services;
 13
 14/// <summary>
 15/// Stores the new plan and schedules it for immediate execution.
 16/// </summary>
 17public class DefaultAlterationPlanScheduler : IAlterationPlanScheduler
 18{
 19    private readonly IWorkflowDefinitionService _workflowDefinitionService;
 20    private readonly IWorkflowDispatcher _workflowDispatcher;
 21    private readonly IIdentityGenerator _identityGenerator;
 22    private readonly IJsonSerializer _jsonSerializer;
 23
 24    /// <summary>
 25    /// Initializes a new instance of the <see cref="DefaultAlterationPlanScheduler"/> class.
 26    /// </summary>
 127    public DefaultAlterationPlanScheduler(IWorkflowDefinitionService workflowDefinitionService, IWorkflowDispatcher work
 28    {
 129        _workflowDefinitionService = workflowDefinitionService;
 130        _workflowDispatcher = workflowDispatcher;
 131        _identityGenerator = identityGenerator;
 132        _jsonSerializer = jsonSerializer;
 133    }
 34
 35    /// <inheritdoc />
 36    public async Task<string> SubmitAsync(AlterationPlanParams planParams, CancellationToken cancellationToken = default
 37    {
 038        if(string.IsNullOrWhiteSpace(planParams.Id))
 039            planParams.Id = _identityGenerator.GenerateId();
 40
 041        var definitionId = ExecuteAlterationPlanWorkflow.WorkflowDefinitionId;
 042        var workflowGraph = await _workflowDefinitionService.FindWorkflowGraphAsync(definitionId, VersionOptions.Publish
 43
 044        if (workflowGraph == null)
 045            throw new($"Workflow definition with ID '{definitionId}' not found");
 46
 047        var serializedPlan = _jsonSerializer.Serialize(planParams);
 048        var request = new DispatchWorkflowDefinitionRequest(workflowGraph.Workflow.Identity.Id)
 049        {
 050            Input = new Dictionary<string, object>
 051            {
 052                ["Plan"] = serializedPlan
 053            }
 054        };
 055        await _workflowDispatcher.DispatchAsync(request, cancellationToken);
 56
 057        return planParams.Id;
 058    }
 59}