【发布时间】:2018-07-07 13:41:30
【问题描述】:
我最近才开始编写 Powershell 脚本。我有一个正在执行负载测试的项目。我运行测试并根据测试结果生成报告。我使用的工具是通过他们的 API 完成的。所以我有 3 个使用 Powershell 脚本发送调用的 Rest API。
第一次调用:启动负载测试,但在配置中设置了多次迭代(可能会运行数小时):
Invoke-RestMethod -Method Post -Uri $StartTestUrl -ContentType "application/json" -OutVariable StartTestResponse -Body $StartTestRequestBody | ConvertTo-Json
第二次调用:获取我们刚刚运行/或仍在运行的负载测试的状态:
Invoke-RestMethod -Method Post -Uri $GetStatusUrl -ContentType "application/json" -OutVariable GetStatusResponse -Body $GetStatusRequestBody | ConvertTo-Json
第三次调用:从完成的测试运行生成报告:
Invoke-RestMethod -Method Post -Uri $GenerateReportUrl -ContentType "application/json" -OutVariable GenerateReportResponse -Body $GenerateReportRequestBody | ConvertTo-Json
目标:我希望能够在 Powershell 中编写一个 DO-WHILE 循环或其他循环,通过每分钟调用第二个 api 来检查响应中的状态“DONE”来检查测试的状态.然后开始第三次通话,因为如果测试未完成,我无法生成报告。
示例:
foreach(var minute in minutes)
{
// if(status.Done)
// {
// CALL GenerateReport
// }
// else
//{
//keep checking every minute
//}
}
【问题讨论】:
标签: c# rest powershell loops scripting