This file contains hidden or 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
public static class ServiceCollectionExtensions | |
{ | |
/// <summary> | |
/// Adds a set of Azure Relays and an associated Request Hanlder. | |
/// </summary> | |
/// <typeparam name="T">The type you wish to be injected as the Request Handler for incoming messages</typeparam> | |
/// <param name="services">Service collection</param> | |
/// <param name="relayConnectionStrings">Array of relay connection strings</param> | |
/// <returns>Service Collection</returns> | |
public static IServiceCollection AddAzureRelayListeners<T> (this IServiceCollection services, params string[] relayConnectionStrings) |
This file contains hidden or 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
public class Worker : IHostedService | |
{ | |
private readonly IEnumerable<IAzureRelayListener> _listeners; | |
private readonly ILogger _logger; | |
public Worker(IEnumerable<IAzureRelayListener> listeners, ILogger<Worker> logger) | |
{ | |
_listeners = listeners; | |
_logger = logger; | |
} |
This file contains hidden or 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
public interface IAzureRelayListener | |
{ | |
Task StartAsync(); | |
Task StopAsync(); | |
} | |
public class AzureRelayListener : IAzureRelayListener | |
{ | |
private readonly HybridConnectionListener _listener; | |
private readonly IRequestHandler _requestHandler; |
This file contains hidden or 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
public class QueuedHostedService : BackgroundService | |
{ | |
private readonly IJobStatusService _jobStatusService; | |
private readonly ILogger _logger; | |
public IBackgroundTaskQueue TaskQueue { get; } | |
public QueuedHostedService(IBackgroundTaskQueue taskQueue, | |
IJobStatusService jobStatusService, | |
ILogger<QueuedHostedService> logger) | |
{ |
This file contains hidden or 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
public interface IBackgroundTaskQueue | |
{ | |
void QueueBackgroundWorkItem(string jobId, Func<CancellationToken, Task> workItem); | |
Task<(string jobId, Func<CancellationToken, Task> func)> DequeueAsync( | |
CancellationToken cancellationToken); | |
} | |
public class BackgroundTaskQueue : IBackgroundTaskQueue | |
{ |
This file contains hidden or 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
public interface IJobStatusService | |
{ | |
void SetState(string jobId, State newState); | |
State GetState(string jobId); | |
} | |
public class JobStatusService : IJobStatusService | |
{ | |
private readonly ConcurrentDictionary<string, State> _jobStatus = new ConcurrentDictionary<string, State>(); |
This file contains hidden or 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
public class GatlingService | |
{ | |
public async Task<RunResults> RunSimulation(RunSettings runSettings) | |
{ | |
var runId = runSettings.RunId; | |
var gatlingStartInfo = new ProcessStartInfo(runSettings.GatlingPath) | |
{ | |
UseShellExecute = false, | |
RedirectStandardOutput = true, | |
RedirectStandardError = true, |
This file contains hidden or 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
public class FileService | |
{ | |
public async Task<RunSettings> CreateRunFolders(Guid runId, Stream requestStream) | |
{ | |
var gatlingHomeFolder = Environment.GetEnvironmentVariable("GATLING_HOME"); | |
using (var memoryStream = new MemoryStream()) | |
{ | |
await requestStream.CopyToAsync(memoryStream); | |
await System.IO.File.WriteAllBytesAsync($"/tmp/{runId}.zip", memoryStream.ToArray()); |
This file contains hidden or 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
[Route("startasync/{runId:guid}")] | |
[HttpPost] | |
public async Task<IActionResult> StartAsync(Guid runId) | |
{ | |
if (ValidateQueryParameters(runId, out var badRequest)) return badRequest; | |
var runSettings = await _fileService.CreateRunFolders(runId, Request.Body); | |
_queue.QueueBackgroundWorkItem(runId.ToString(), async token => | |
{ |
This file contains hidden or 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
[Route("start/{runId:guid}")] | |
[HttpPost] | |
public async Task<IActionResult> Start(Guid runId, [FromQuery] bool returnReport) | |
{ | |
if (ValidateQueryParameters(runId, out var badRequest)) return badRequest; | |
var runSettings = await _fileService.CreateRunFolders(runId, Request.Body); | |
if (returnReport) | |
{ |
NewerOlder