Skip to content

Commit

Permalink
repro asp.net core app for #11
Browse files Browse the repository at this point in the history
  • Loading branch information
adams85 committed Jun 3, 2020
1 parent b1488fc commit 617c6bb
Show file tree
Hide file tree
Showing 20 changed files with 816 additions and 0 deletions.
10 changes: 10 additions & 0 deletions test/issue11/ArticleCollection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;

namespace Itg.Persistence.Secondary
{
[Serializable]
public class ArticleCollection
{
public byte[] Data { get; set; }
}
}
20 changes: 20 additions & 0 deletions test/issue11/BackgroundTaskQueue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;

namespace issue11
{
internal class BackgroundTaskQueue : IBackgroundTaskQueue
{
private readonly Channel<object> _queue = Channel.CreateUnbounded<object>(new UnboundedChannelOptions
{
AllowSynchronousContinuations = false,
SingleReader = true,
SingleWriter = false,
});

public async Task EnqueueAsync(object order, CancellationToken ct) => await _queue.Writer.WriteAsync(order, ct);

public async Task<object> DequeueAsync(CancellationToken ct) => await _queue.Reader.ReadAsync(ct);
}
}
24 changes: 24 additions & 0 deletions test/issue11/Controllers/TestController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace issue11.Controllers
{
[ApiController]
public class MainController : ControllerBase
{
private readonly IBackgroundTaskQueue _taskQueue;

public MainController(IBackgroundTaskQueue taskQueue)
{
_taskQueue = taskQueue;
}

[Route("[action]")]
public async Task<ActionResult> Test()
{
await _taskQueue.EnqueueAsync(new CreateCollectionBackgroundWork.Order(), HttpContext.RequestAborted);

return Ok();
}
}
}
43 changes: 43 additions & 0 deletions test/issue11/CreateCollectionBackgroundWork.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System.Threading;
using System.Threading.Tasks;
using Itg.Persistence.Secondary;
using Microsoft.Extensions.Logging;

namespace issue11
{
public static class CreateCollectionBackgroundWork
{
public class Order : IBackgroundWorkOrder<Order, Worker>
{
/* contains parameters for it's worker*/
}

public class Worker : IBackgroundWorker<Order, Worker>
{
private readonly ILogger _logger;
private readonly ShopArticleService _articleService;
private readonly IKeyValueStore<ArticleCollection> _collectionStore;

public Worker(
ILoggerFactory loggerFactory,
ShopArticleService articleService,
/* ^ logging works inside this; into integra-<counter> ^ */
IKeyValueStore<ArticleCollection> collectionStore
/* ^ the logger in this (FileKeyValueStore) is the one not logging to the file, but does to console, and logs also appear when the config file is reloaded ^ */)
{
this._logger = loggerFactory.CreateLogger(nameof(CreateCollectionBackgroundWork));
// ^ this is actually still logging to integra-<counter> file ^

_articleService = articleService;
_collectionStore = collectionStore;
}

public async Task DoWork(Order order, CancellationToken ct)
{
var model = await _articleService.GetArticleCollectionAsync();

await _collectionStore.Set("test", model, ct);
}
}
}
}
11 changes: 11 additions & 0 deletions test/issue11/IBackgroundTaskQueue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Threading;
using System.Threading.Tasks;

namespace issue11
{
public interface IBackgroundTaskQueue
{
Task EnqueueAsync(object order, CancellationToken ct);
Task<object> DequeueAsync(CancellationToken ct);
}
}
6 changes: 6 additions & 0 deletions test/issue11/IBackgroundWorkOrder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace issue11
{
internal interface IBackgroundWorkOrder<TOrder, TWorker>
{
}
}
6 changes: 6 additions & 0 deletions test/issue11/IBackgroundWorker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace issue11
{
public interface IBackgroundWorker<TOrder, TWorker>
{
}
}
Loading

0 comments on commit 617c6bb

Please sign in to comment.