< Summary

Information
Class: Elsa.Alterations.Services.DefaultAlterationJobRunner
Assembly: Elsa.Alterations
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Alterations/Services/DefaultAlterationJobRunner.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 26
Coverable lines: 26
Total lines: 58
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
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%210%
RunAsync()0%620%

File(s)

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

#LineLine coverage
 1using Elsa.Alterations.Core.Contracts;
 2using Elsa.Alterations.Core.Entities;
 3using Elsa.Alterations.Core.Enums;
 4using Elsa.Alterations.Core.Filters;
 5using Elsa.Alterations.Core.Notifications;
 6using Elsa.Common;
 7using Elsa.Mediator.Contracts;
 8
 9namespace Elsa.Alterations.Services;
 10
 11/// <inheritdoc />
 12public class DefaultAlterationJobRunner : IAlterationJobRunner
 13{
 14    private readonly IAlterationPlanStore _alterationPlanStore;
 15    private readonly IAlterationJobStore _alterationJobStore;
 16    private readonly IAlterationRunner _alterationRunner;
 17    private readonly INotificationSender _notificationSender;
 18    private readonly ISystemClock _systemClock;
 19
 20    /// <summary>
 21    /// Initializes a new instance of the <see cref="DefaultAlterationJobRunner"/> class.
 22    /// </summary>
 023    public DefaultAlterationJobRunner(
 024        IAlterationPlanStore alterationPlanStore,
 025        IAlterationJobStore alterationJobStore,
 026        IAlterationRunner alterationRunner,
 027        INotificationSender notificationSender,
 028        ISystemClock systemClock)
 29    {
 030        _alterationPlanStore = alterationPlanStore;
 031        _alterationJobStore = alterationJobStore;
 032        _alterationRunner = alterationRunner;
 033        _notificationSender = notificationSender;
 034        _systemClock = systemClock;
 035    }
 36
 37    /// <inheritdoc />
 38    public async Task<AlterationJob> RunAsync(string jobId, CancellationToken cancellationToken = default)
 39    {
 040        var job = (await _alterationJobStore.FindAsync(new AlterationJobFilter { Id = jobId }, cancellationToken))!;
 041        var plan = (await _alterationPlanStore.FindAsync(new AlterationPlanFilter { Id = job.PlanId }, cancellationToken
 042        var workflowInstanceId = job.WorkflowInstanceId;
 43
 044        job.Status = AlterationJobStatus.Running;
 045        job.StartedAt = _systemClock.UtcNow;
 046        await _alterationJobStore.SaveAsync(job, cancellationToken);
 47
 048        var result = await _alterationRunner.RunAsync(workflowInstanceId, plan.Alterations, cancellationToken);
 49
 050        job.Status = result.IsSuccessful ? AlterationJobStatus.Completed : AlterationJobStatus.Failed;
 051        job.Log = result.Log.LogEntries.ToList();
 052        job.CompletedAt = _systemClock.UtcNow;
 053        await _alterationJobStore.SaveAsync(job, cancellationToken);
 054        await _notificationSender.SendAsync(new AlterationJobCompleted(job, result.WorkflowHasScheduledWork), cancellati
 55
 056        return job;
 057    }
 58}