Files
monorepo/LCU.API.Internal.Dispatcher/LCU.Library.Internal.DispatcherModels/Entities/WorkItem.cs
T
2026-03-24 15:26:03 -05:00

48 lines
1.7 KiB
C#

using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using LCU.Library.Internal.DispatcherModels.Enums;
using LCU.Library.Internal.DispatcherModels.Helpers;
namespace LCU.Library.Internal.DispatcherModels.Entities;
public class WorkItem
{
public int WorkItemId { get; set; }
public int JobId { get; set; }
[Required]
[StringLength(200, ErrorMessage = "Name Max Length is 200")]
public string Name { get; set; }
[StringLength(8000, ErrorMessage = "Description Max Length is 8000")]
public string Description { get; set; }
[Required]
public int Order { get; set; }
public string SerializedPayload { get; set; }
public string Url { get; set; }
public HttpMethodType HttpMethod { get; set; }
[Required]
public ActionType ActionType { get; set; }
public bool CancelJobOnFailure { get; set; }
public int CancelJobLimit { get; set; }
public int CanceledJobCounter { get; set; }
[ForeignKey("WorkItemId")]
public ICollection<WorkItemExecution> WorkItemExecutions { get; set; }
[NotMapped]
public WorkItemExecution CurrentWorkItemExecution
{
get
{
var currentWorkItemExecution = WorkItemExecutions?.FirstOrDefault(wie => wie.CompletedTimestamp == null);
if (currentWorkItemExecution != null)
{
currentWorkItemExecution = Clone.DeepClone(currentWorkItemExecution);
}
return currentWorkItemExecution;
}
}
[NotMapped]
public bool IsNewWorkItem => WorkItemId <= 0;
[NotMapped]
public bool RequiresJobCancellation => CancelJobOnFailure && CanceledJobCounter <= CancelJobLimit;
}