Skip to content

Commit

Permalink
Merge pull request #125 from Poltuu/dep_chanel
Browse files Browse the repository at this point in the history
UP dependencies
  • Loading branch information
Poltuu authored Sep 2, 2020
2 parents 6940357 + 9f9413f commit ac0f099
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 37 deletions.
21 changes: 10 additions & 11 deletions Harpoon.Common/Background/BackgroundQueue.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
using System;
using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;

namespace Harpoon.Background
{
internal class BackgroundQueue<T>
{
private readonly ConcurrentQueue<T> _workItems = new ConcurrentQueue<T>();
private readonly SemaphoreSlim _signal = new SemaphoreSlim(0);
private readonly Channel<T> _channel = Channel.CreateUnbounded<T>(new UnboundedChannelOptions
{
SingleReader = true,
SingleWriter = true
});

public void QueueWebHook(T workItem)
public ValueTask QueueWebHookAsync(T workItem)
{
if (workItem == null)
{
throw new ArgumentException(nameof(workItem));
}

_workItems.Enqueue(workItem);
_signal.Release();
return _channel.Writer.WriteAsync(workItem);
}

public async Task<T> DequeueAsync(CancellationToken cancellationToken)
public ValueTask<T> DequeueAsync(CancellationToken cancellationToken)
{
await _signal.WaitAsync(cancellationToken);
_workItems.TryDequeue(out var workItem);

return workItem;
return _channel.Reader.ReadAsync(cancellationToken);
}
}
}
5 changes: 2 additions & 3 deletions Harpoon.Common/Background/BackgroundSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ public BackgroundSender(BackgroundQueue<IWebHookWorkItem> webHooksQueue)
_webHooksQueue = webHooksQueue ?? throw new ArgumentNullException(nameof(webHooksQueue));
}

public Task SendAsync(IWebHookWorkItem webHookWorkItem, CancellationToken cancellationToken = default)
public async Task SendAsync(IWebHookWorkItem webHookWorkItem, CancellationToken cancellationToken = default)
{
if (webHookWorkItem == null)
{
throw new ArgumentNullException(nameof(webHookWorkItem));
}

_webHooksQueue.QueueWebHook(webHookWorkItem);
return Task.CompletedTask;
await _webHooksQueue.QueueWebHookAsync(webHookWorkItem);
}
}
}
5 changes: 2 additions & 3 deletions Harpoon.Common/DefaultWebHookService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ public DefaultWebHookService(BackgroundQueue<IWebHookNotification> webHooksQueue
_webHooksQueue = webHooksQueue ?? throw new ArgumentNullException(nameof(webHooksQueue));
}

public Task NotifyAsync(IWebHookNotification notification, CancellationToken cancellationToken = default)
public async Task NotifyAsync(IWebHookNotification notification, CancellationToken cancellationToken = default)
{
if (notification == null)
{
throw new ArgumentNullException(nameof(notification));
}

_webHooksQueue.QueueWebHook(notification);
return Task.CompletedTask;
await _webHooksQueue.QueueWebHookAsync(notification);
}
}
}
8 changes: 4 additions & 4 deletions Harpoon.Common/Harpoon.Common.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>Harpoon</RootNamespace>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
Expand All @@ -21,9 +21,9 @@

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.3" />
<PackageReference Include="Microsoft.Extensions.Http" Version="3.1.3" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="3.1.3" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.7" />
<PackageReference Include="Microsoft.Extensions.Http" Version="3.1.7" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="3.1.7" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions Harpoon.Controllers/Harpoon.Controllers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" Version="3.1.3" PrivateAssets="all" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.4.1" />
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="3.1.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.5.1" />
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="3.1.7" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Harpoon.MassTransit/Harpoon.MassTransit.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<AssemblyVersion>0.1.5</AssemblyVersion>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<AssemblyVersion>0.1.5</AssemblyVersion>
Expand All @@ -20,7 +20,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.7" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions Harpoon.Registrations/Harpoon.Registrations.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<AssemblyVersion>0.1.5</AssemblyVersion>
Expand All @@ -20,8 +20,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.OpenApi" Version="1.2.0" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection" Version="3.1.3" />
<PackageReference Include="Microsoft.OpenApi" Version="1.2.3" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection" Version="3.1.7" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Harpoon.Tests/BackgroundSenderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public async Task NormalAsync()
var count = 0;

await service.SendAsync(new WebHookWorkItem(Guid.NewGuid(), new WebHookNotification("", new object()), new WebHook()), CancellationToken.None);
await queue.DequeueAsync(CancellationToken.None).ContinueWith(t => count++);
await queue.DequeueAsync(CancellationToken.None).AsTask().ContinueWith(t => count++);

Assert.Equal(1, count);
}
Expand Down
2 changes: 1 addition & 1 deletion Harpoon.Tests/DefaultWebHookServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public async Task DefaultWebHookServiceAsync()
var count = 0;

await service.NotifyAsync(new WebHookNotification("", new object()));
await queue.DequeueAsync(CancellationToken.None).ContinueWith(t => count++);
await queue.DequeueAsync(CancellationToken.None).AsTask().ContinueWith(t => count++);

Assert.Equal(1, count);
}
Expand Down
12 changes: 6 additions & 6 deletions Harpoon.Tests/Harpoon.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@
<PackageReference Include="MassTransit.AspNetCore" Version="6.2.5" />
<PackageReference Include="MassTransit.RabbitMQ" Version="6.2.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="Moq" Version="4.14.1" />
<PackageReference Include="Moq" Version="4.14.5" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.2">
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" Version="3.1.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection" Version="3.1.3" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="3.1.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.3" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection" Version="3.1.7" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="3.1.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.7" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.3" />
</ItemGroup>

Expand Down

0 comments on commit ac0f099

Please sign in to comment.