public async Task TestPostStatusUpdate() { string controllerEndpoint = "https://localhost:44379/"; StatusesConnector connector = StatusesConnector.GetConnector(controllerEndpoint); try { BacktestJobStatus status = new BacktestJobStatus() { Attributes = new List <BacktestStatusAttribute>() { new BacktestStatusAttribute() { Name = "Attribute1", Value = "Value1" }, new BacktestStatusAttribute() { Name = "Attribute2", Value = "Value2" } }, Message = "Test Message", Progress = 50, Timestamp = DateTimeOffset.Now }; var result = await connector.PostBacktestJobStatus("RegTestJob", status); Assert.IsTrue(result.Success, result.Message); } catch (Exception ex) { Assert.Fail(ex.Message); } }
internal GenericActionResult HandleStatusUpdate(string backtestJobName, BacktestJobStatus status) { if (status == null) { return(new GenericActionResult(false, "Invalid status object: null")); } logger.Debug($"Processing status update for {backtestJobName}"); return(jobsControllerUtils.AddStatusUpdate(backtestJobName, status)); }
internal GenericActionResult AddStatusUpdate(string jobName, BacktestJobStatus status) { //statusesDict.AddOrUpdate(jobName, (key) => //{ // logger.Info($"Record status update for new job {jobName}"); // return status; //}, (key, oldValue) => //{ // logger.Debug($"Record status update for job {jobName}"); // return status; //}); //if (!statusesDict.ContainsKey(jobName)) //{ // logger.Info($"Record status update for new job {jobName}"); // statusesDict.Add(jobName, status); //} //else //{ // logger.Debug($"Record status update for job {jobName}"); // UpdateAttributes(statusesDict[jobName].Attributes, status.Attributes); // statusesDict[jobName].CompletionTime = status.CompletionTime; // statusesDict[jobName].Message = status.Message; // statusesDict[jobName].Progress = status.Progress; // statusesDict[jobName].StatusCode = status.StatusCode; // statusesDict[jobName].Timestamp = status.Timestamp; //} return(new GenericActionResult(true, "Not used")); //BacktestJob job; //if (activeJobs.TryGetValue(jobName, out job)) //{ // job.Output.Status = status; // activeJobs.AddOrUpdate(jobName, job, (key, oldValue) => job); // return new GenericActionResult(true, $"Updated status of job {jobName}"); //} //else //{ // string err = $"Not updating status of unknown job {jobName}"; // logger.Error(err); // return new GenericActionResult(false, err); //} }
public static BacktestJobStatusModel ToBacktestStatusModel(this BacktestJobStatus status) { if (status == null) { return(null); } return(new BacktestJobStatusModel() { ActualStartTime = status.ActualStartTime, Attributes = status.Attributes.ToBacktestStatusAttributeModels(), CompletionTime = status.CompletionTime, Message = status.Message, Progress = status.Progress, StatusCode = status.StatusCode, Timestamp = (status.Timestamp > DateTimeOffset.MinValue) ? status.Timestamp.ToLocalTime() : (DateTimeOffset?)null, Worker = status.Worker }); }
public async Task <GenericActionResult> PostBacktestJobStatus(string backtestJobName, BacktestJobStatus status, CancellationToken ct = default(CancellationToken)) { try { ct.ThrowIfCancellationRequested(); if (string.IsNullOrEmpty(backtestJobName)) { throw new ArgumentNullException(nameof(backtestJobName)); } if (status == null) { throw new ArgumentNullException(nameof(status)); } logger.Info($"About to send POST request to {controllerEndpoint}/api/statuses/{backtestJobName}"); return(await controllerEndpoint.AppendPathSegment($"/api/statuses/{backtestJobName}").PostJsonAsync(status, ct).ReceiveJson <GenericActionResult>()); } catch (OperationCanceledException) { string err = "Not posting status update: operation cancelled"; logger.Error(err); return(new GenericActionResult(false, err)); } catch (ArgumentNullException ex) { string err = $"Not posting status update: missing or invalid parameter {ex.ParamName}"; logger.Error(err); return(new GenericActionResult(false, err)); } catch (Exception ex) { string err = "Failed to post status update"; logger.Error(err, ex); return(new GenericActionResult(false, $"{err}: {ex.Message}")); } }
public GenericActionResult Post(string backtestJobName, [FromBody] BacktestJobStatus status) { return(utils.HandleStatusUpdate(backtestJobName, status)); }