public async Task <RunResult> LaunchAsync(Algorithm algorithm, Run run, RunSettings settings) { // Todo: Change this to some mapping probably, dont include Runs which contains current run // Probably create some model to transfer all data needed.. algorithm.Runs.Clear(); var message = new CreateAlgorithmMessage() { Run = run, Algorithm = algorithm, Arguments = settings.Arguments, Timeout = settings.Timeout }; try { var result = await _brokerSender.SendAsync(message); if (result?.Exception != null) { var innerExc = (ApiException)Activator.CreateInstance(result.Exception); throw new RemoteException(innerExc); } return(result); } catch (TimeoutException) { _logger.LogError("Timeouted when sending message to broker (Alg Server is failing or not any is connected)"); } return(new RunResult() { Result = RunResultType.NotFinished, RunId = run.Id }); }
private async Task <RunResultMessage> ProcessInternalAsync(CreateAlgorithmMessage request) { _logger.LogInformation("Processing message - Run Id: " + request.Run.Id); using (_container.OpenScope()) { using (var uow = _unitOfWorkProvider.Create(DbContextOptions.DisableTransactionMode)) { uow.Context.Runs.Attach(request.Run); var result = await _launchService.LaunchAsync(request.Algorithm, request.Run, new RunSettings { Arguments = request.Arguments, Timeout = request.Timeout }); return(new RunResultMessage() { StdOut = result.StdOut, StdErr = result.StdErr, CreatedAt = result.CreatedAt, FinishedAt = result.FinishedAt, FileId = result.FileId, Result = result.Result, RunId = result.RunId }); } } }
public async Task <RunResultMessage> SendAsync(CreateAlgorithmMessage message, TimeSpan timeout) { var result = await SendAsync(message).WithTimeout(timeout); if (result.Completed) { throw new TimeoutException(); } return(result.Value); }
public Task <RunResultMessage> SendAsync(CreateAlgorithmMessage msg) { var message = "Hello World"; var body = Encoding.UTF8.GetBytes(message); var properties = _channel.CreateBasicProperties(); _channel.BasicPublish(exchange: "", routingKey: QueueName, basicProperties: properties, body: body); Console.WriteLine(" [x] Sent {0}", message); return(null); }
public async Task <RunResultMessage> ProcessAsync(CreateAlgorithmMessage request) { try { return(await ProcessInternalAsync(request)); } catch (ApiException ex) { return(new RunResultMessage() { Exception = ex.GetType() }); } catch (UnauthorizedAccessException) { return(new RunResultMessage() { Exception = typeof(UnauthorizedAccessException) }); } }
public Task <RunResultMessage> SendAsync(CreateAlgorithmMessage message) { return(_bus.RequestAsync <CreateAlgorithmMessage, RunResultMessage>(message)); }
public Task <RunResultMessage> SendAsync(CreateAlgorithmMessage message, TimeSpan timeout) { throw new NotImplementedException(); }