< Summary - Kestrun — Combined Coverage

Information
Class: Kestrun.Scheduling.RoslynJobFactory
Assembly: Kestrun
File(s): /home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Scheduling/RoslynJobFactory.cs
Tag: Kestrun/Kestrun@9d3a582b2d63930269564a7591aa77ef297cadeb
Line coverage
100%
Covered lines: 33
Uncovered lines: 0
Coverable lines: 33
Total lines: 77
Line coverage: 100%
Branch coverage
72%
Covered branches: 13
Total branches: 18
Branch coverage: 72.2%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Build(...)80%1010100%
Build(...)62.5%88100%

File(s)

/home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Scheduling/RoslynJobFactory.cs

#LineLine coverage
 1using Kestrun.Languages;
 2using Kestrun.SharedState;
 3using Microsoft.CodeAnalysis.CSharp;
 4using Serilog.Events;
 5using System.Reflection;
 6
 7namespace Kestrun.Scheduling;
 8
 9internal static class RoslynJobFactory
 10{
 11    public static Func<CancellationToken, Task> Build(
 12        string code,
 13        Serilog.ILogger log,
 14        string[]? extraImports,
 15        Assembly[]? extraRefs,
 16        IReadOnlyDictionary<string, object?>? locals,
 17        LanguageVersion languageVersion = LanguageVersion.CSharp12)
 18    {
 619        if (log.IsEnabled(LogEventLevel.Debug))
 20        {
 621            log.Debug("Building C# job, code length={Length}, imports={ImportsCount}, refs={RefsCount}, lang={Lang}",
 622                code?.Length, extraImports?.Length ?? 0, extraRefs?.Length ?? 0, languageVersion);
 23        }
 24
 625        var script = CSharpDelegateBuilder.Compile(code: code, log: log, extraImports: extraImports, extraRefs: extraRef
 526        var runner = script.CreateDelegate();   // returns ScriptRunner<object?>
 527        if (log.IsEnabled(LogEventLevel.Debug))
 28        {
 529            log.Debug("C# job runner created, type={Type}", runner.GetType());
 30        }
 31        /* 5️⃣  Returned delegate = *execute only* */
 532        return async ct =>
 533        {
 534            if (log.IsEnabled(LogEventLevel.Debug))
 535            {
 536                log.Debug("Executing C# job at {Now:O}", DateTimeOffset.UtcNow);
 537            }
 538
 539            var globals = locals is { Count: > 0 }
 540                ? new CsGlobals(SharedStateStore.Snapshot(), locals)
 541                : new CsGlobals(SharedStateStore.Snapshot());
 542            _ = await runner(globals, ct).ConfigureAwait(false);
 1043        };
 44    }
 45
 46
 47
 48    public static Func<CancellationToken, Task> Build(
 49       string code,
 50       Serilog.ILogger log,
 51       string[]? extraImports,
 52       Assembly[]? extraRefs,
 53       IReadOnlyDictionary<string, object?>? locals,
 54       Microsoft.CodeAnalysis.VisualBasic.LanguageVersion languageVersion = Microsoft.CodeAnalysis.VisualBasic.LanguageV
 55    {
 156        if (log.IsEnabled(LogEventLevel.Debug))
 57        {
 158            log.Debug("Building C# job, code length={Length}, imports={ImportsCount}, refs={RefsCount}, lang={Lang}",
 159                code?.Length, extraImports?.Length ?? 0, extraRefs?.Length ?? 0, languageVersion);
 60        }
 61
 162        var script = VBNetDelegateBuilder.Compile<object>(code: code, log: log, extraImports: extraImports, extraRefs: e
 63
 164        return async ct =>
 165        {
 166            if (log.IsEnabled(LogEventLevel.Debug))
 167            {
 168                log.Debug("Executing C# job at {Now:O}", DateTimeOffset.UtcNow);
 169            }
 170
 171            var globals = new CsGlobals(SharedStateStore.Snapshot());
 172            _ = await script(globals).ConfigureAwait(false);
 273        };
 74    }
 75}
 76
 77