< Summary

Information
Class: Elsa.Common.RecurringTasks.RecurringTaskScheduleManager
Assembly: Elsa.Common
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Common/RecurringTasks/RecurringTaskScheduleManager.cs
Line coverage
84%
Covered lines: 11
Uncovered lines: 2
Coverable lines: 13
Total lines: 31
Line coverage: 84.6%
Branch coverage
60%
Covered branches: 6
Total branches: 10
Branch coverage: 60%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_ScheduledTasks()100%11100%
GetScheduleFor(...)66.66%66100%
CreateSchedule(...)50%5466.66%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Common/RecurringTasks/RecurringTaskScheduleManager.cs

#LineLine coverage
 1using Cronos;
 2using Microsoft.Extensions.Options;
 3
 4namespace Elsa.Common.RecurringTasks;
 5
 16public class RecurringTaskScheduleManager(IOptions<RecurringTaskOptions> options, ISystemClock systemClock)
 7{
 78    public IDictionary<Type, ISchedule> ScheduledTasks { get; set; } = new Dictionary<Type, ISchedule>();
 9
 10    public ISchedule GetScheduleFor(Type taskType)
 11    {
 312        if (!ScheduledTasks.TryGetValue(taskType, out var schedule))
 13        {
 314            var intervalExpression = options.Value.Schedule.ScheduledTasks.TryGetValue(taskType, out var expr) ? expr : 
 315            schedule = intervalExpression != null ? CreateSchedule(intervalExpression) : new IntervalSchedule(TimeSpan.F
 316            ScheduledTasks[taskType] = schedule;
 17        }
 18
 319        return schedule;
 20    }
 21
 22    private ISchedule CreateSchedule(IntervalExpression intervalExpression)
 23    {
 324        return intervalExpression.Type switch
 325        {
 026            IntervalExpressionType.Cron => new CronSchedule(systemClock, CronExpression.Parse(intervalExpression.Express
 327            IntervalExpressionType.Interval => new IntervalSchedule(TimeSpan.Parse(intervalExpression.Expression)),
 028            _ => throw new NotSupportedException($"Interval expression type '{intervalExpression.Type}' is not supported
 329        };
 30    }
 31}