【发布时间】:2021-11-16 05:32:41
【问题描述】:
我是 Python 新手。我写了一个scheduled python 2.7 script 来检查web service URL 的问题。
#The external system's vendor provides a public sample server that can be used for testing purposes:
#https://sampleserver6.arcgisonline.com/arcgis/rest/services/ServiceRequest/MapServer/1/query?where=SUBMITDT%3CDATE%272018-05-11%27&f=pjson&returnCountOnly=true
try:
result = fetch_row_count(url)
if result == 0:
print "All records are synced. No need to do anything."
elif result is None:
#Comm Template CGGISWO_ERROR: "The Collector WO map service had an error when pinged by the CGGISSERVICE escalation."
# "Check for WOs that have not been synced to Maximo."
ctMboSet = mbo.getMboSet("$commtemp", "COMMTEMPLATE", "TEMPLATEID ='CGGISWO_ERROR'")
ctMbo = ctMboSet.getMbo(0)
ctMbo.sendMessage(mbo, mbo)
elif result > 0:
#Comm Template CGGISWO_NOSYNC: "There are Collector WOs that have not been synced to Maximo."
# "The WO COLLECTOR map service has records from previous days that need to be synced."
ctMboSet = mbo.getMboSet("$commtemp", "COMMTEMPLATE", "TEMPLATEID ='CGGISWO_NOSYNC'")
ctMbo = ctMboSet.getMbo(0)
ctMbo.sendMessage(mbo, mbo)
except:
#Comm Template CGGISWO_TIMEOUT: "The Collector WO map service timed-out when pinged by the CGGISSERVICE escalation."
# "Check for WOs that have not been synced to Maximo.""
ctMboSet = mbo.getMboSet("$commtemp", "COMMTEMPLATE", "TEMPLATEID ='CGGISWO_TIMEOUT'")
ctMbo = ctMboSet.getMbo(0)
ctMbo.sendMessage(mbo, mbo)
我的问题是关于网络服务挂起和脚本超时的场景。
我尝试使用except 处理这种情况。但我不确定如何测试它是否真的有效(如果网络服务挂起)。
有没有一种方法可以 ping 当前挂起的 Web 服务 - 以查看我的脚本是否有效?是否存在始终(故意)挂起的公共示例 Web 服务之类的东西?
【问题讨论】:
-
这里有问题。您正在调用
fetch_row_count两次,这可能会导致两次超时。另外,如果它确实返回 None,你的第一个if语句将引发TypeError,你应该这样做result = fetch_count(url)/if result is None:/# handle error/elif result > 0:/# handle success。 -
是的,我认为这更可靠。
标签: python python-2.7 monitoring maximo arcgis-server