Initial Commit;
This commit is contained in:
13
InServiceQue.Core/InServiceQue.Core.csproj
Normal file
13
InServiceQue.Core/InServiceQue.Core.csproj
Normal file
@@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
7
InServiceQue.Core/Models/IQueueTask.cs
Normal file
7
InServiceQue.Core/Models/IQueueTask.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace InServiceQue.Core.Models;
|
||||
|
||||
public interface IQueueTask
|
||||
{
|
||||
string GetTypeString();
|
||||
string GetPayloadString();
|
||||
}
|
||||
45
InServiceQue.Core/Models/QueueTask.cs
Normal file
45
InServiceQue.Core/Models/QueueTask.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
namespace InServiceQue.Core.Models;
|
||||
|
||||
public class QueueTask: IQueueTask
|
||||
{
|
||||
private string _type;
|
||||
public Guid Id { get; init; }
|
||||
public string TaskType { get; init; } = default!;
|
||||
public DateTime DateCreated { get; init; }
|
||||
public DateTime? DateProcessed { get; private set; }
|
||||
public DateTime? DateClosed { get; private set; }
|
||||
public int Attempts { get; private set; }
|
||||
public string? Payload { get; init; }
|
||||
|
||||
|
||||
public QueueTask(string taskType, string? payload)
|
||||
{
|
||||
Id = Guid.NewGuid();
|
||||
TaskType = taskType;
|
||||
DateCreated = DateTime.UtcNow;
|
||||
Payload = payload;
|
||||
}
|
||||
|
||||
public QueueTask(IQueueTask task): this(task.GetTypeString(), task.GetPayloadString()) { }
|
||||
|
||||
public void MarkAttempt()
|
||||
{
|
||||
DateProcessed = DateTime.UtcNow;
|
||||
Attempts++;
|
||||
}
|
||||
|
||||
public void SolveTask()
|
||||
{
|
||||
DateClosed = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
string IQueueTask.GetTypeString()
|
||||
{
|
||||
return TaskType;
|
||||
}
|
||||
|
||||
string IQueueTask.GetPayloadString()
|
||||
{
|
||||
return Payload ?? string.Empty;
|
||||
}
|
||||
}
|
||||
20
InServiceQue.Core/Repositories/ITaskRepository.cs
Normal file
20
InServiceQue.Core/Repositories/ITaskRepository.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System.Data;
|
||||
using InServiceQue.Core.Models;
|
||||
|
||||
namespace InServiceQue.Core.Repositories;
|
||||
|
||||
public interface ITaskRepository: IDisposable
|
||||
{
|
||||
void Insert(QueueTask task);
|
||||
Task InsertAsync(QueueTask task);
|
||||
IDbTransaction StartTransaction();
|
||||
Task<IDbTransaction> StartTransactionAsync();
|
||||
void CommitTransaction(IDbTransaction tx);
|
||||
Task CommitTransactionAsync(IDbTransaction tx);
|
||||
void RollbackTransaction(IDbTransaction tx);
|
||||
Task RollbackTransactionAsync(IDbTransaction tx);
|
||||
QueueTask? GetNextTask(IDbTransaction tx);
|
||||
Task<QueueTask?> GetNextTaskAsync(IDbTransaction tx);
|
||||
void SaveTask(QueueTask task, IDbTransaction tx);
|
||||
Task SaveTaskAsync(QueueTask task, IDbTransaction tx);
|
||||
}
|
||||
Reference in New Issue
Block a user