public static StatusType GetStatus(IExecuteController ec, string planName, long id) { int c = 0; StatusType status = StatusType.New; while (c < 30) { System.Threading.Thread.Sleep(1000); try { Enum.TryParse(ec.GetPlanElements(planName, id, "Result:Status").ToString(), out status); } catch { } c = status < StatusType.Success ? c + 1 : int.MaxValue; } return(status); }
public static T ExecuteAsync <T>(IExecuteController ec, string planName, StartPlanEnvelope pe, string path = "Actions[0]:Result:ExitData") { long id = ec.StartPlan(pe, planName); StatusType status = Task.Run(() => GetStatus(ec, planName, id)).Result; if (status == StatusType.Success) { return(YamlHelpers.Deserialize <T>(ec.GetPlanElements(planName, id, path).ToString())); } else { return(default(T)); } }
public static object WaitForTerminalStatusOrTimeout(IExecuteController ec, string planName, long id, string path = "Actions[0]:Result:ExitData", SerializationType serializationType = SerializationType.Json, int pollingIntervalSeconds = 1, int timeoutSeconds = 120) { StatusType status = Task.Run(() => GetStatus(ec, planName, id, pollingIntervalSeconds, timeoutSeconds)).Result; try { return(ec.GetPlanElements(planName, id, path, serializationType, setContentType: false)); } catch { return(status); } }
public static StatusType GetStatus(IExecuteController ec, string planName, long id, int pollingIntervalSeconds = 1, int timeoutSeconds = 120) { //ensure valid values pollingIntervalSeconds = pollingIntervalSeconds < 1 ? 1 : pollingIntervalSeconds; timeoutSeconds = timeoutSeconds < 1 ? 120 : timeoutSeconds; int c = 0; StatusType status = StatusType.New; while (c < timeoutSeconds) { Thread.Sleep(pollingIntervalSeconds * 1000); try { Enum.TryParse(ec.GetPlanElements(planName, id, "Result:Status", setContentType: false).ToString(), out status); } catch { } c = status < StatusType.Success ? c + 1 : int.MaxValue; } return(status); }