Files
T
2026-03-24 15:26:03 -05:00

98 lines
2.7 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using LCU.Library.Internal.ApiResponse.Models;
using LCU.Library.Internal.DispatcherModels.Enums;
using LCU.Library.Internal.DispatcherModels.Models;
namespace LCU.Library.Internal.DispatcherModels.Entities;
public class Job : Errorable
{
public int JobId { get; set; }
[Required]
[StringLength(200, ErrorMessage = "Requesting Application Max Length is 200")]
public string RequestingApplication { 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]
[StringLength(200, ErrorMessage = "Created by Max Length is 200")]
public string CreatedBy { get; set; }
public DateTime CreatedAt { get; set; }
[StringLength(200, ErrorMessage = "Modified by Max Length is 200")]
public string ModifiedBy { get; set; }
public DateTime? ModifiedDate { get; set; }
public string CronSchedule { get; set; }
public DateTime? NextRunTime { get; set; }
public DateTime? SoftDeleteDate { get; set; }
public bool SkipHolidays { get; set; } = false;
public JobStatus JobStatus { get; set; } = JobStatus.Inactive;
[ForeignKey("JobId")]
public ICollection<JobErrorRecipient> JobErrorRecipients { get; set; } = new List<JobErrorRecipient>();
[ForeignKey("JobId")]
public ICollection<JobTag> JobTags { get; set; } = new List<JobTag>();
[Required]
[ForeignKey("JobId")]
public ICollection<WorkItem> WorkItems { get; set; } = new List<WorkItem>();
[NotMapped]
public bool IsNewJob
{
get
{
return JobId <= 0;
}
}
public void ResetRunTimeAndStatus()
{
NextRunTime = null;
JobStatus = JobStatus.Inactive;
}
[NotMapped]
public bool IsPending
{
get
{
return WorkItems.All(workItem => workItem.CurrentWorkItemExecution == null);
}
}
[NotMapped]
public StatusType CurrentStatus
{
get
{
if (NextRunTime == null)
{
return StatusType.Inactive;
}
var currentWorkItem = WorkItems.FirstOrDefault(workItem => workItem.CurrentWorkItemExecution != null);
return IsPending || currentWorkItem == null ? StatusType.Pending : currentWorkItem.CurrentWorkItemExecution.Status;
}
}
[NotMapped]
public ReturnResponse ReturnResponse { get; set; }
}