mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-20 21:33:15 -07:00
Finished #633 (First part of the queuing)
This commit is contained in:
parent
1c7fb2e93e
commit
2bd7ece9d0
10 changed files with 460 additions and 155 deletions
|
@ -34,6 +34,7 @@ namespace PlexRequests.Core.Models
|
|||
RequestApproved,
|
||||
AdminNote,
|
||||
Test,
|
||||
|
||||
RequestDeclined,
|
||||
ItemAddedToFaultQueue
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,6 +39,10 @@
|
|||
<HintPath>..\packages\Common.Logging.Core.3.0.0\lib\net40\Common.Logging.Core.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Dapper, Version=1.50.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Dapper.1.50.0-beta8\lib\net45\Dapper.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Mono.Data.Sqlite">
|
||||
<HintPath>..\Assemblies\Mono.Data.Sqlite.dll</HintPath>
|
||||
</Reference>
|
||||
|
@ -105,6 +109,7 @@
|
|||
<Compile Include="Notification\Templates\IEmailBasicTemplate.cs" />
|
||||
<Compile Include="Notification\TransportType.cs" />
|
||||
<Compile Include="PlexReadOnlyDatabase.cs" />
|
||||
<Compile Include="Queue\ITransientFaultQueue.cs" />
|
||||
<Compile Include="Queue\TransientFaultQueue.cs" />
|
||||
<Compile Include="SettingModels\AuthenticationSettings.cs" />
|
||||
<Compile Include="SettingModels\ExternalSettings.cs" />
|
||||
|
|
17
PlexRequests.Core/Queue/ITransientFaultQueue.cs
Normal file
17
PlexRequests.Core/Queue/ITransientFaultQueue.cs
Normal file
|
@ -0,0 +1,17 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using PlexRequests.Store;
|
||||
using PlexRequests.Store.Models;
|
||||
|
||||
namespace PlexRequests.Core.Queue
|
||||
{
|
||||
public interface ITransientFaultQueue
|
||||
{
|
||||
void Dequeue();
|
||||
Task DequeueAsync();
|
||||
IEnumerable<RequestQueue> GetQueue();
|
||||
Task<IEnumerable<RequestQueue>> GetQueueAsync();
|
||||
void QueueItem(RequestedModel request, RequestType type, FaultType faultType);
|
||||
Task QueueItemAsync(RequestedModel request, RequestType type, FaultType faultType);
|
||||
}
|
||||
}
|
|
@ -26,7 +26,9 @@
|
|||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Dapper;
|
||||
using PlexRequests.Helpers;
|
||||
using PlexRequests.Store;
|
||||
using PlexRequests.Store.Models;
|
||||
|
@ -34,7 +36,7 @@ using PlexRequests.Store.Repository;
|
|||
|
||||
namespace PlexRequests.Core.Queue
|
||||
{
|
||||
public class TransientFaultQueue
|
||||
public class TransientFaultQueue : ITransientFaultQueue
|
||||
{
|
||||
public TransientFaultQueue(IRepository<RequestQueue> queue)
|
||||
{
|
||||
|
@ -44,44 +46,84 @@ namespace PlexRequests.Core.Queue
|
|||
private IRepository<RequestQueue> RequestQueue { get; }
|
||||
|
||||
|
||||
public void QueueItem(RequestedModel request, RequestType type)
|
||||
public void QueueItem(RequestedModel request, RequestType type, FaultType faultType)
|
||||
{
|
||||
//Ensure there is not a duplicate queued item
|
||||
var existingItem = RequestQueue.Custom(
|
||||
connection =>
|
||||
{
|
||||
connection.Open();
|
||||
var result = connection.Query<RequestQueue>("select * from RequestQueue where PrimaryIdentifier = @ProviderId", new { ProviderId = request.ProviderId });
|
||||
|
||||
return result;
|
||||
}).FirstOrDefault();
|
||||
|
||||
if (existingItem != null)
|
||||
{
|
||||
// It's already in the queue
|
||||
return;
|
||||
}
|
||||
|
||||
var queue = new RequestQueue
|
||||
{
|
||||
Type = type,
|
||||
Content = ByteConverterHelper.ReturnBytes(request),
|
||||
PrimaryIdentifier = request.ProviderId
|
||||
PrimaryIdentifier = request.ProviderId,
|
||||
FaultType = faultType
|
||||
};
|
||||
RequestQueue.Insert(queue);
|
||||
}
|
||||
|
||||
public async Task QueueItemAsync(RequestedModel request, RequestType type)
|
||||
public async Task QueueItemAsync(RequestedModel request, RequestType type, FaultType faultType)
|
||||
{
|
||||
//Ensure there is not a duplicate queued item
|
||||
var existingItem = await RequestQueue.CustomAsync(async connection =>
|
||||
{
|
||||
connection.Open();
|
||||
var result = await connection.QueryAsync<RequestQueue>("select * from RequestQueue where PrimaryIdentifier = @ProviderId", new { ProviderId = request.ProviderId });
|
||||
|
||||
return result;
|
||||
});
|
||||
|
||||
if (existingItem.FirstOrDefault() != null)
|
||||
{
|
||||
// It's already in the queue
|
||||
return;
|
||||
}
|
||||
|
||||
var queue = new RequestQueue
|
||||
{
|
||||
Type = type,
|
||||
Content = ByteConverterHelper.ReturnBytes(request),
|
||||
PrimaryIdentifier = request.ProviderId
|
||||
PrimaryIdentifier = request.ProviderId,
|
||||
FaultType = faultType
|
||||
};
|
||||
await RequestQueue.InsertAsync(queue);
|
||||
}
|
||||
|
||||
public IEnumerable<RequestQueue> Dequeue()
|
||||
public IEnumerable<RequestQueue> GetQueue()
|
||||
{
|
||||
var items = RequestQueue.GetAll();
|
||||
|
||||
RequestQueue.DeleteAll("RequestQueue");
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<RequestQueue>> DequeueAsync()
|
||||
public async Task<IEnumerable<RequestQueue>> GetQueueAsync()
|
||||
{
|
||||
var items = RequestQueue.GetAllAsync();
|
||||
|
||||
await RequestQueue.DeleteAllAsync("RequestQueue");
|
||||
|
||||
|
||||
return await items;
|
||||
}
|
||||
|
||||
public void Dequeue()
|
||||
{
|
||||
RequestQueue.DeleteAll("RequestQueue");
|
||||
}
|
||||
|
||||
public async Task DequeueAsync()
|
||||
{
|
||||
await RequestQueue.DeleteAllAsync("RequestQueue");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
<packages>
|
||||
<package id="Common.Logging" version="3.0.0" targetFramework="net45" />
|
||||
<package id="Common.Logging.Core" version="3.0.0" targetFramework="net45" />
|
||||
<package id="Dapper" version="1.50.0-beta8" targetFramework="net45" />
|
||||
<package id="Nancy" version="1.4.3" targetFramework="net45" />
|
||||
<package id="Nancy.Authentication.Forms" version="1.4.1" targetFramework="net45" />
|
||||
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net45" />
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue