【问题标题】:How to test for web service URL hanging?如何测试 Web 服务 URL 挂起?
【发布时间】: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


【解决方案1】:

源系统 (Maximo) 有自己的 Web 服务 (OSLC)。我能够设置一个可以调用的虚假服务/URL...它使用 Python 睡眠功能故意挂起。


import time

time.sleep(300)
responseBody = "5 minute delay (300) seconds."

Run an automation script via a URL


当我从“睡眠”URL 上的原始问题运行脚本时,我可以看到我的 try/except 正在正确处理睡眠 URL。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-10-11
    • 1970-01-01
    • 2015-12-15
    • 2015-08-19
    • 1970-01-01
    • 1970-01-01
    • 2015-06-04
    • 1970-01-01
    相关资源
    最近更新 更多