< Summary - Syki

Information
Class: Syki.Back.Commands.Domain.Commands.Command
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Domain/Commands/Command.cs
Tag: 97_27801654829
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 Syki.Back.Domain.Institutions;
 3
 4namespace Syki.Back.Commands.Domain.Commands;
 5
 6public class Command
 7{
 3288    public int Id { get; set; }
 369    public int InstitutionId { get; set; }
 131210    public string Type { get; set; }
 65611    public string Data { get; set; }
 32812    public CommandStatus Status { get; set; }
 32813    public DateTime CreatedAt { get; set; }
 32814    public int Duration { get; set; }
 32815    public DateTime? ProcessedAt { get; set; }
 016    public Guid? ProcessorId { get; set; }
 65617    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>
 32823    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>
 32830    public int? OriginalId { get; set; }
 31
 32    /// <summary>
 33    /// Id do lote que contém o comando
 34    /// </summary>
 32835    public int? BatchId { get; set; }
 36
 32837    public DateTime? NotBefore { get; set; }
 38
 98439    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>
 33045    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>
 32856    public BackoffStrategy BackoffStrategy { get; set; }
 57
 58    /// <summary>
 59    /// Base delay in seconds used by the backoff formula. Default is 5.
 60    /// </summary>
 32861    public int BaseDelaySeconds { get; set; }
 62
 98663    public List<string> Logs { get; set; } = [];
 64
 29265    public Institution? Institution { get; set; }
 66
 66067    public Command() { }
 68
 29269    public Command(
 29270        Institution institution,
 29271        object data,
 29272        int? parentId = null,
 29273        int? originalId = null,
 29274        int? batchId = null,
 29275        int? delaySeconds = null,
 29276        string? activityId = null,
 29277        int maxRetries = 0,
 29278        BackoffStrategy backoffStrategy = BackoffStrategy.None,
 29279        int baseDelaySeconds = 5
 29280    ) {
 29281        Institution = institution;
 29282        Type = data.GetType().Name;
 29283        Data = data.Serialize();
 29284        CreatedAt = DateTime.UtcNow;
 29285        ParentId = parentId;
 29286        OriginalId = originalId;
 29287        BatchId = batchId;
 29288        ActivityId = activityId;
 29289        NotBefore = delaySeconds != null ? DateTime.UtcNow.AddSeconds(delaySeconds.Value) : null;
 29290        MaxRetries = maxRetries;
 29291        BackoffStrategy = backoffStrategy;
 29292        BaseDelaySeconds = baseDelaySeconds;
 29293    }
 94
 3695    public Command(
 3696        int institutionId,
 3697        object data,
 3698        int? parentId = null,
 3699        int? originalId = null,
 36100        int? batchId = null,
 36101        int? delaySeconds = null,
 36102        string? activityId = null,
 36103        int maxRetries = 0,
 36104        BackoffStrategy backoffStrategy = BackoffStrategy.None,
 36105        int baseDelaySeconds = 5
 36106    ) {
 36107        InstitutionId = institutionId;
 36108        Type = data.GetType().Name;
 36109        Data = data.Serialize();
 36110        CreatedAt = DateTime.UtcNow;
 36111        ParentId = parentId;
 36112        OriginalId = originalId;
 36113        BatchId = batchId;
 36114        ActivityId = activityId;
 36115        NotBefore = delaySeconds != null ? DateTime.UtcNow.AddSeconds(delaySeconds.Value) : null;
 36116        MaxRetries = maxRetries;
 36117        BackoffStrategy = backoffStrategy;
 36118        BaseDelaySeconds = baseDelaySeconds;
 36119    }
 120
 121    public void SetAwaiting()
 122    {
 0123        Status = CommandStatus.Awaiting;
 0124    }
 125
 126    public void Processed(double duration)
 127    {
 328128        ProcessedAt = DateTime.UtcNow;
 328129        Duration = Convert.ToInt32(duration);
 328130        Status = Error.HasValue() ? CommandStatus.Error : CommandStatus.Success;
 328131    }
 132
 133    public ActivityContext GetParentActivityContext()
 134    {
 328135        ActivityContext.TryParse(ActivityId, null, out var parsedContext);
 328136        return parsedContext;
 137    }
 138}