首页 > 解决方案 > 如何在批处理脚本中添加while循环以检查给定次数尝试的状态

问题描述

我有一个 tabadmin refreshextract 脚本,它工作正常,但现在我们想从气流中实现它,唯一的问题是如果会话重新连接,然后气流在日志中给出错误,但最终它成功刷新。

我们添加了 psql 查询来查找,一旦刷新提取完成,它将提取成功或失败的信息。

tabcmd refreshextracts --url workbook_url -s https:// -t site -u tabadmin --password-file C:\Users\abc\Desktop\passwd.txt --no-certcheck

伪代码

cd c:\Program Files\PostgreSQL\11\bin
refresh_status='N'
retry_count = 0
while refresh_status = 'N' and retry_count < 20
retry_count++
refresh_status = $(psql -p 8060 -h servername -U readonly -d workgroup -c " select case when lower(notes) like '%finished%'  == 'succeed' then 'Y' else 'N" as refresh_status from _background_tasks where Job_name = 'Refresh Extracts' and title = 'workbook_name'  and  created_at >=CURRENT_DATE ORDER BY created_at desc limit 1")
if refresh_status == 'Y'
    EXIT Success
else
    continue
continue
if refresh_status = 'N'
    exit ERROR

标签: batch-filetableau-api

解决方案


这应该工作

@echo off
set attempts=0
:loop
set /a attempts+=1
if %attempts%==5 (echo %attempts%)
goto loop

或这个

@echo off
set attempts=0
:loop
set /a attempts+=1
echo %attempts%
goto loop

顺便说一句,这些都是例子。


推荐阅读