0

I'm a Python novice. I've written a scheduled python 2.7 script for checking a web service URL for issues.

#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)

My question is about the scenario where the web service hangs and the script times-out.

I've tried to handle that scenario with except. But I'm not sure how to how to test if that will actually work or not (if the web service hangs).

Is there a way I can ping a web service that is currently hanging -- to see if my script works or not? Is there such a thing as a public sample web service that is always hanging (on purpose)?

User1974
  • 276
  • 1
  • 17
  • 63
  • 1
    There's an issue here. You are calling `fetch_row_count` twice, which could potentially incur two timeouts. Plus, if it does return None, your first `if` statement will raise a `TypeError`, You should do `result = fetch_count(url)` / `if result is None:` / `# handle error` / `elif result > 0:` / `# handle success`. – Tim Roberts Nov 16 '21 at 17:26
  • Yes, I think that is more solid. – Tim Roberts Nov 16 '21 at 19:19

1 Answers1

0

The source system (Maximo) has a web service of its own (OSLC). I was able to set up a fake service/URL that can be called...it hangs on purpose by using the Python sleep function.

enter image description here


import time

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

Run an automation script via a URL


When I run my script from the original question on the "sleep" URL, I can see that my try/except is handling the sleeping URL correctly.

User1974
  • 276
  • 1
  • 17
  • 63