/// <summary> /// Converts the instance into a public <see cref="WorkflowStatus"/>. /// </summary> public WorkflowStatus ToPublic() { var executionState = new WorkflowStatus() { Execution = this.Execution.ToPublic(), TypeName = this.WorkflowType.Name, WorkflowCloseStatus = (WorkflowExecutionCloseStatus)this.WorkflowCloseStatus, HistoryLength = this.HistoryLength, ParentDomain = this.ParentDomainId, ExecutionTime = ComputeExecutionTime(), Memo = this.Memo?.Fields }; if (this.StartTime > 0) { executionState.StartTime = CadenceHelper.UnixNanoToDateTimeUtc(this.StartTime); } if (this.CloseTime > 0) { executionState.CloseTime = CadenceHelper.UnixNanoToDateTimeUtc(this.CloseTime); } return(executionState); }
/// <summary> /// Hack to compute the workflowm execution time. /// </summary> /// <returns>The execution <see cref="TimeSpan"/>.</returns> private TimeSpan ComputeExecutionTime() { // $hack(jefflill): // // This hack mitigates: // // https://github.com/nforgeio/neonKUBE/issues/759 if (this.StartTime > 0 && this.CloseTime > 0) { return(CadenceHelper.UnixNanoToDateTimeUtc(this.StartTime) - CadenceHelper.UnixNanoToDateTimeUtc(this.CloseTime)); } else if (this.StartTime > 0) { var executionTime = DateTime.UtcNow - CadenceHelper.UnixNanoToDateTimeUtc(this.StartTime); // It's possible for this calculation to come out negative when the Cadence server // and client machine clock time is different. We'll just return zero when this // happens. if (executionTime < TimeSpan.Zero) { executionTime = TimeSpan.Zero; } return(executionTime); } else { return(TimeSpan.Zero); } }
/// <summary> /// Converts the instance to a <see cref="PollerInfo"/>. /// </summary> /// <returns>The converted <see cref="PollerInfo"/>.</returns> public PollerInfo ToPublic() { return(new PollerInfo() { LastAccessTime = CadenceHelper.UnixNanoToDateTimeUtc(this.LastAccessTime), Identity = this.Identity, RatePerSecond = this.RatePerSecond }); }