< Summary

Information
Class: Elsa.Alterations.Activities.DispatchAlterationJobs
Assembly: Elsa.Alterations
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Alterations/Activities/DispatchAlterationJobs.cs
Line coverage
13%
Covered lines: 4
Uncovered lines: 26
Coverable lines: 30
Total lines: 73
Line coverage: 13.3%
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%
.ctor(...)100%210%
get_PlanId()100%11100%
ExecuteAsync()0%2040%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Alterations/Activities/DispatchAlterationJobs.cs

#LineLine coverage
 1using System.ComponentModel;
 2using System.Runtime.CompilerServices;
 3using Elsa.Alterations.Core.Contracts;
 4using Elsa.Alterations.Core.Enums;
 5using Elsa.Alterations.Core.Filters;
 6using Elsa.Workflows;
 7using Elsa.Workflows.Attributes;
 8using Elsa.Workflows.Exceptions;
 9using Elsa.Workflows.Memory;
 10using Elsa.Workflows.Models;
 11
 12namespace Elsa.Alterations.Activities;
 13
 14/// <summary>
 15/// Submits an alteration plan for execution.
 16/// </summary>
 17[Browsable(false)]
 18[Activity("Elsa", "Alterations", "Dispatches jobs for the specified Alteration Plan", Kind = ActivityKind.Task)]
 19public class DispatchAlterationJobs : CodeActivity
 20{
 21    /// <inheritdoc />
 1922    public DispatchAlterationJobs(Variable<string> planId, [CallerFilePath] string? source = null, [CallerLineNumber] in
 23    {
 1924        PlanId = new Input<string>(planId);
 1925    }
 26
 27    /// <inheritdoc />
 028    public DispatchAlterationJobs([CallerFilePath] string? source = null, [CallerLineNumber] int? line = null) : base(so
 29    {
 030    }
 31
 32    /// <summary>
 33    /// The ID of the alteration plan.
 34    /// </summary>
 6735    public Input<string> PlanId { get; set; } = null!;
 36
 37    /// <inheritdoc />
 38    protected override async ValueTask ExecuteAsync(ActivityExecutionContext context)
 39    {
 040        var cancellationToken = context.CancellationToken;
 041        var planId = context.Get(PlanId)!;
 042        var alterationPlanStore = context.GetRequiredService<IAlterationPlanStore>();
 043        var planFilter = new AlterationPlanFilter
 044        {
 045            Id = planId
 046        };
 047        var plan = await alterationPlanStore.FindAsync(planFilter, cancellationToken);
 48
 049        if (plan == null)
 050            throw new FaultException(AlterationFaultCodes.PlanNotFound, AlterationFaultCategories.Alteration, DefaultFau
 51
 52        // Update status.
 053        plan.Status = AlterationPlanStatus.Dispatching;
 054        await alterationPlanStore.SaveAsync(plan, cancellationToken);
 55
 56        // Find all jobs for the plan and dispatch them.
 057        var filter = new AlterationJobFilter
 058        {
 059            PlanId = plan.Id
 060        };
 061        var alterationJobStore = context.GetRequiredService<IAlterationJobStore>();
 062        var alterationJobIds = await alterationJobStore.FindManyIdsAsync(filter, cancellationToken);
 63
 64        // Dispatch each job.
 065        var alterationJobDispatcher = context.GetRequiredService<IAlterationJobDispatcher>();
 066        foreach (var jobId in alterationJobIds)
 067            await alterationJobDispatcher.DispatchAsync(jobId, cancellationToken);
 68
 69        // Update status.
 070        plan.Status = AlterationPlanStatus.Running;
 071        await alterationPlanStore.SaveAsync(plan, cancellationToken);
 072    }
 73}