< 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: 56_26538939494
Line coverage
95%
Covered lines: 76
Uncovered lines: 4
Coverable lines: 80
Total lines: 139
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.Enums;
 3using Syki.Back.Domain.Institutions;
 4
 5namespace Syki.Back.Commands.Domain.Commands;
 6
 7public class Command
 8{
 3049    public int Id { get; set; }
 3610    public int InstitutionId { get; set; }
 121611    public string Type { get; set; }
 60812    public string Data { get; set; }
 30413    public CommandStatus Status { get; set; }
 30414    public DateTime CreatedAt { get; set; }
 30415    public int Duration { get; set; }
 30416    public DateTime? ProcessedAt { get; set; }
 017    public Guid? ProcessorId { get; set; }
 60818    public string? Error { get; set; }
 19
 20    /// <summary>
 21    /// Id do comando que gerou o comando
 22    /// Utilizado quando um comando gera outro em seu handler
 23    /// </summary>
 30424    public int? ParentId { get; set; }
 25
 26    /// <summary>
 27    /// Id do comando com erro que gerou o comando atual
 28    /// Utilizado quando o comando original está com erro e é reprocessado
 29    /// O comando atual é uma cópia do original (imutabilidade)
 30    /// </summary>
 30431    public int? OriginalId { get; set; }
 32
 33    /// <summary>
 34    /// Id do lote que contém o comando
 35    /// </summary>
 30436    public int? BatchId { get; set; }
 37
 30438    public DateTime? NotBefore { get; set; }
 39
 91240    public string? ActivityId { get; set; }
 41
 42    /// <summary>
 43    /// Número máximo de tentativas de reprocessamento automático do comando.
 44    /// Quando o comando falha e MaxRetries > 0, um novo comando de retry é criado com MaxRetries - 1.
 45    /// </summary>
 30646    public int MaxRetries { get; set; }
 47
 48    /// <summary>
 49    /// Which retry attempt this is. 0 for the original command, 1 for first retry, etc.
 50    /// </summary>
 051    public int RetryAttempt { get; set; }
 52
 53    /// <summary>
 54    /// Backoff strategy for computing delay between retries.
 55    /// When None (default), retries are immediate.
 56    /// </summary>
 30457    public BackoffStrategy BackoffStrategy { get; set; }
 58
 59    /// <summary>
 60    /// Base delay in seconds used by the backoff formula. Default is 5.
 61    /// </summary>
 30462    public int BaseDelaySeconds { get; set; }
 63
 91464    public List<string> Logs { get; set; } = [];
 65
 26866    public Institution? Institution { get; set; }
 67
 61268    public Command() { }
 69
 26870    public Command(
 26871        Institution institution,
 26872        object data,
 26873        int? parentId = null,
 26874        int? originalId = null,
 26875        int? batchId = null,
 26876        int? delaySeconds = null,
 26877        string? activityId = null,
 26878        int maxRetries = 0,
 26879        BackoffStrategy backoffStrategy = BackoffStrategy.None,
 26880        int baseDelaySeconds = 5
 26881    ) {
 26882        Institution = institution;
 26883        Type = data.GetType().Name;
 26884        Data = data.Serialize();
 26885        CreatedAt = DateTime.UtcNow;
 26886        ParentId = parentId;
 26887        OriginalId = originalId;
 26888        BatchId = batchId;
 26889        ActivityId = activityId;
 26890        NotBefore = delaySeconds != null ? DateTime.UtcNow.AddSeconds(delaySeconds.Value) : null;
 26891        MaxRetries = maxRetries;
 26892        BackoffStrategy = backoffStrategy;
 26893        BaseDelaySeconds = baseDelaySeconds;
 26894    }
 95
 3696    public Command(
 3697        int institutionId,
 3698        object data,
 3699        int? parentId = null,
 36100        int? originalId = null,
 36101        int? batchId = null,
 36102        int? delaySeconds = null,
 36103        string? activityId = null,
 36104        int maxRetries = 0,
 36105        BackoffStrategy backoffStrategy = BackoffStrategy.None,
 36106        int baseDelaySeconds = 5
 36107    ) {
 36108        InstitutionId = institutionId;
 36109        Type = data.GetType().Name;
 36110        Data = data.Serialize();
 36111        CreatedAt = DateTime.UtcNow;
 36112        ParentId = parentId;
 36113        OriginalId = originalId;
 36114        BatchId = batchId;
 36115        ActivityId = activityId;
 36116        NotBefore = delaySeconds != null ? DateTime.UtcNow.AddSeconds(delaySeconds.Value) : null;
 36117        MaxRetries = maxRetries;
 36118        BackoffStrategy = backoffStrategy;
 36119        BaseDelaySeconds = baseDelaySeconds;
 36120    }
 121
 122    public void SetAwaiting()
 123    {
 0124        Status = CommandStatus.Awaiting;
 0125    }
 126
 127    public void Processed(double duration)
 128    {
 304129        ProcessedAt = DateTime.UtcNow;
 304130        Duration = Convert.ToInt32(duration);
 304131        Status = Error.HasValue() ? CommandStatus.Error : CommandStatus.Success;
 304132    }
 133
 134    public ActivityContext GetParentActivityContext()
 135    {
 304136        ActivityContext.TryParse(ActivityId, null, out var parsedContext);
 304137        return parsedContext;
 138    }
 139}