< Summary - Estud

Information
Class: Estud.Back.Domain.Commands.Command
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Domain/Commands/Command.cs
Tag: 114_29044117136
Line coverage
95%
Covered lines: 76
Uncovered lines: 4
Coverable lines: 80
Total lines: 138
Line coverage: 95%
Branch coverage
50%
Covered branches: 3
Total branches: 6
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Id()100%11100%
get_InstitutionId()100%11100%
get_Type()100%11100%
get_Data()100%11100%
get_Status()100%11100%
get_CreatedAt()100%11100%
get_Duration()100%11100%
get_ProcessedAt()100%11100%
get_ProcessorId()100%210%
get_Error()100%11100%
get_ParentId()100%11100%
get_OriginalId()100%11100%
get_BatchId()100%11100%
get_NotBefore()100%11100%
get_ActivityId()100%11100%
get_MaxRetries()100%11100%
get_RetryAttempt()100%210%
get_BackoffStrategy()100%11100%
get_BaseDelaySeconds()100%11100%
get_Logs()100%11100%
get_Institution()100%11100%
.ctor()100%11100%
.ctor(...)50%22100%
.ctor(...)50%22100%
SetAwaiting()100%210%
Processed(...)50%22100%
GetParentActivityContext()100%11100%

File(s)

/home/runner/work/syki/syki/Back/Domain/Commands/Command.cs

#LineLine coverage
 1using System.Diagnostics;
 2using Estud.Back.Domain.Institutions;
 3
 4namespace Estud.Back.Domain.Commands;
 5
 6public class Command
 7{
 8088    public int Id { get; set; }
 549    public int InstitutionId { get; set; }
 323210    public string Type { get; set; }
 161611    public string Data { get; set; }
 80812    public CommandStatus Status { get; set; }
 80813    public DateTime CreatedAt { get; set; }
 80814    public int Duration { get; set; }
 80815    public DateTime? ProcessedAt { get; set; }
 016    public Guid? ProcessorId { get; set; }
 161617    public string? Error { get; set; }
 18
 19    /// <summary>
 20    /// Id do comando que gerou o comando
 21    /// Utilizado quando um comando gera outro em seu handler
 22    /// </summary>
 80823    public int? ParentId { get; set; }
 24
 25    /// <summary>
 26    /// Id do comando com erro que gerou o comando atual
 27    /// Utilizado quando o comando original está com erro e é reprocessado
 28    /// O comando atual é uma cópia do original (imutabilidade)
 29    /// </summary>
 80830    public int? OriginalId { get; set; }
 31
 32    /// <summary>
 33    /// Id do lote que contém o comando
 34    /// </summary>
 80835    public int? BatchId { get; set; }
 36
 80837    public DateTime? NotBefore { get; set; }
 38
 242439    public string? ActivityId { get; set; }
 40
 41    /// <summary>
 42    /// Número máximo de tentativas de reprocessamento automático do comando.
 43    /// Quando o comando falha e MaxRetries > 0, um novo comando de retry é criado com MaxRetries - 1.
 44    /// </summary>
 81045    public int MaxRetries { get; set; }
 46
 47    /// <summary>
 48    /// Which retry attempt this is. 0 for the original command, 1 for first retry, etc.
 49    /// </summary>
 050    public int RetryAttempt { get; set; }
 51
 52    /// <summary>
 53    /// Backoff strategy for computing delay between retries.
 54    /// When None (default), retries are immediate.
 55    /// </summary>
 80856    public BackoffStrategy BackoffStrategy { get; set; }
 57
 58    /// <summary>
 59    /// Base delay in seconds used by the backoff formula. Default is 5.
 60    /// </summary>
 80861    public int BaseDelaySeconds { get; set; }
 62
 242663    public List<string> Logs { get; set; } = [];
 64
 75465    public Institution? Institution { get; set; }
 66
 162067    public Command() { }
 68
 75469    public Command(
 75470        Institution institution,
 75471        object data,
 75472        int? parentId = null,
 75473        int? originalId = null,
 75474        int? batchId = null,
 75475        int? delaySeconds = null,
 75476        string? activityId = null,
 75477        int maxRetries = 0,
 75478        BackoffStrategy backoffStrategy = BackoffStrategy.None,
 75479        int baseDelaySeconds = 5
 75480    ) {
 75481        Institution = institution;
 75482        Type = data.GetType().Name;
 75483        Data = data.Serialize();
 75484        CreatedAt = DateTime.UtcNow;
 75485        ParentId = parentId;
 75486        OriginalId = originalId;
 75487        BatchId = batchId;
 75488        ActivityId = activityId;
 75489        NotBefore = delaySeconds != null ? DateTime.UtcNow.AddSeconds(delaySeconds.Value) : null;
 75490        MaxRetries = maxRetries;
 75491        BackoffStrategy = backoffStrategy;
 75492        BaseDelaySeconds = baseDelaySeconds;
 75493    }
 94
 5495    public Command(
 5496        int institutionId,
 5497        object data,
 5498        int? parentId = null,
 5499        int? originalId = null,
 54100        int? batchId = null,
 54101        int? delaySeconds = null,
 54102        string? activityId = null,
 54103        int maxRetries = 0,
 54104        BackoffStrategy backoffStrategy = BackoffStrategy.None,
 54105        int baseDelaySeconds = 5
 54106    ) {
 54107        InstitutionId = institutionId;
 54108        Type = data.GetType().Name;
 54109        Data = data.Serialize();
 54110        CreatedAt = DateTime.UtcNow;
 54111        ParentId = parentId;
 54112        OriginalId = originalId;
 54113        BatchId = batchId;
 54114        ActivityId = activityId;
 54115        NotBefore = delaySeconds != null ? DateTime.UtcNow.AddSeconds(delaySeconds.Value) : null;
 54116        MaxRetries = maxRetries;
 54117        BackoffStrategy = backoffStrategy;
 54118        BaseDelaySeconds = baseDelaySeconds;
 54119    }
 120
 121    public void SetAwaiting()
 122    {
 0123        Status = CommandStatus.Awaiting;
 0124    }
 125
 126    public void Processed(double duration)
 127    {
 808128        ProcessedAt = DateTime.UtcNow;
 808129        Duration = Convert.ToInt32(duration);
 808130        Status = Error.HasValue() ? CommandStatus.Error : CommandStatus.Success;
 808131    }
 132
 133    public ActivityContext GetParentActivityContext()
 134    {
 808135        ActivityContext.TryParse(ActivityId, null, out var parsedContext);
 808136        return parsedContext;
 137    }
 138}