簡體   English   中英

如何在批處理腳本中添加while循環以檢查給定次數嘗試的狀態

[英]How to add while loop in batch script to check status for given number of time attempts

我有一個 tabadmin refreshextract 腳本,它工作正常,但現在我們想從 airflow 實現它,唯一的問題是如果 session 重新連接,然后 Z2528F15A184A14D75D2E092E3Z 成功刷新日志,但最終它成功了。

我們添加了 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

這應該工作

@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

順便說一句,這些都是例子。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM