Adding
This commit is contained in:
+17
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace LCU.Library.Internal.DispatcherModels.Entities
|
||||
{
|
||||
public class CleanUpJobSetting
|
||||
{
|
||||
public int CleanUpJobSettingId { get; set; }
|
||||
[Required]
|
||||
[Range(-1000, 0, ErrorMessage = "Value must be 0 or a negative number. ")]
|
||||
public int CompletionDaysPast { get; set; }
|
||||
[ForeignKey("CleanUpJobSettingId")]
|
||||
public ICollection<CleanUpJobTag> CleanUpJobTags { get; set; }
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace LCU.Library.Internal.DispatcherModels.Entities
|
||||
{
|
||||
public class CleanUpJobTag
|
||||
{
|
||||
public int CleanUpJobTagId { get; set; }
|
||||
[Required]
|
||||
public int CleanUpJobSettingId { get; set; }
|
||||
public int TagId { get; set; }
|
||||
[ForeignKey("TagId")]
|
||||
public Tag Tag { get; set; }
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
namespace LCU.Library.Internal.DispatcherModels.Entities;
|
||||
|
||||
public class ExecutionMessage
|
||||
{
|
||||
public ExecutionMessage()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public ExecutionMessage(int workItemExecutionId, string message)
|
||||
{
|
||||
WorkItemExecutionId = workItemExecutionId;
|
||||
Message = message;
|
||||
User = Environment.UserName;
|
||||
MessageDate = DateTime.Now;
|
||||
}
|
||||
|
||||
public int ExecutionMessageId { get; set; }
|
||||
[Required]
|
||||
public int WorkItemExecutionId { get; set; }
|
||||
public string User { get; set; }
|
||||
public DateTime? MessageDate { get; set; }
|
||||
public string Message { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
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; }
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
namespace LCU.Library.Internal.DispatcherModels.Entities;
|
||||
|
||||
public class JobErrorRecipient
|
||||
{
|
||||
public int JobErrorRecipientId { get; set; }
|
||||
public int JobId { get; set; }
|
||||
public string Recipient { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
namespace LCU.Library.Internal.DispatcherModels.Entities;
|
||||
|
||||
public class JobTag
|
||||
{
|
||||
public int JobTagId { get; set; }
|
||||
public int JobId { get; set; }
|
||||
public int TagId { get; set; }
|
||||
[ForeignKey("TagId")]
|
||||
public Tag Tag { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
namespace LCU.Library.Internal.DispatcherModels.Entities;
|
||||
|
||||
public class Tag
|
||||
{
|
||||
public int TagId { get; set; }
|
||||
[Required]
|
||||
[StringLength(300, ErrorMessage = "Requesting Application Max Length is 300")]
|
||||
public string TagName { get; set; }
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
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;
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using LCU.Library.Internal.DispatcherModels.Enums;
|
||||
using LCU.Library.Internal.DispatcherModels.Models;
|
||||
namespace LCU.Library.Internal.DispatcherModels.Entities;
|
||||
|
||||
public class WorkItemExecution : Errorable
|
||||
{
|
||||
public WorkItemExecution()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public WorkItemExecution(int workItemId)
|
||||
{
|
||||
WorkItemId = workItemId;
|
||||
Status = StatusType.Processing;
|
||||
StartedTimestamp = DateTime.Now;
|
||||
}
|
||||
|
||||
public int WorkItemExecutionId { get; set; }
|
||||
[Required]
|
||||
public int WorkItemId { get; set; }
|
||||
[Required]
|
||||
public StatusType Status { get; set; }
|
||||
public DateTime? StartedTimestamp { get; set; }
|
||||
public DateTime? CompletedTimestamp { get; set; }
|
||||
[ForeignKey("WorkItemExecutionId")]
|
||||
public ICollection<ExecutionMessage> ExecutionMessages { get; set; }
|
||||
|
||||
public static WorkItemExecution SetAsFinal(WorkItemExecution workItemExecution, StatusType finalStatus)
|
||||
{
|
||||
workItemExecution.Status = finalStatus;
|
||||
workItemExecution.CompletedTimestamp = DateTime.Now;
|
||||
return workItemExecution;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user