public IActionResult Calc([FromBody] PumpCalcCommand request) { try { _actorSystem .ActorOf( Props.Create(() => new PumpCalcActor(_httpClientFactory, _factory.CreateLogger(typeof(PumpCalcActor)))), request.CalculationUuid ) .Tell(request); } catch (Exception e) { _logger.LogError(e, $"Actor instantiation exception for CalculationUuid {request.CalculationUuid}."); return(BadRequest()); } return(Accepted()); }
private async Task Handler(PumpCalcCommand command, ICalcCommandHandlerWithCallback <PumpCalcCommand> handler) { var sw = new Stopwatch(); sw.Start(); _logger.LogInformation($"[START] [{Self.Path}].Received Command at {DateTime.Now}, with payload: {JsonConvert.SerializeObject(command)}"); try { await handler.Calculate(command, _cancel.Token); await handler.SuccessCallback(command, _httpClientFactory.CreateClient()); } catch (Exception e) { _logger.LogError(e, "Handler exception."); await handler.ErrorCallback(command, _httpClientFactory.CreateClient()); } finally { _logger.LogInformation($"[END] [{Self.Path}].Handled Command at {DateTime.Now}, total seconds - {sw.Elapsed.TotalSeconds}"); Context.Stop(_self); } }