-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
816 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace issue11 | ||
{ | ||
internal interface IBackgroundWorkOrder<TOrder, TWorker> | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace issue11 | ||
{ | ||
public interface IBackgroundWorker<TOrder, TWorker> | ||
{ | ||
} | ||
} |
Oops, something went wrong.