AnsweredAssumed Answered

GP service retruns default result

Question asked by wmakari on Jul 24, 2015
Latest reply on Jul 27, 2015 by JQuinn-esristaff

Dear all,

 

I have a python script gp service that is doing something quite simple, connecting to a Netezza data warehouse and return a string of distinct values from one table column see script below

 

# Import modules
import arcpy,os,time

# Python environment
arcpy.env.overwriteOutput = True

conFile = r"PathToConnectionFile\connection.sde"
arcpy.AddMessage("Set connection file")
inFC = conFile + "\DBNAME.DBA.TABLENAME"
arcpy.AddMessage("Set update table from netezza")
sOrgan = arcpy.GetParameterAsText(0)
startTime = arcpy.GetParameterAsText(1)
endTime = arcpy.GetParameterAsText(2)
Assets = arcpy.GetParameterAsText(3)

arcpy.AddMessage("Input parameters set")

 

field = "FIELDNAME"
arcpy.AddMessage("Field set")
#where clause
sWhere = "ORG_ID='" + sOrgan + "' and UPDATE_TIMESTAMP BETWEEN timestamp '" + startTime + "' and timestamp '" + endTime + "'"

arcpy.AddMessage("Where clause set")
s=""

arcpy.AddMessage("Selecting distinct values")
try:
    # search cursor wrapped in list generator creating list of all value
    arcpy.AddMessage("Inside try")
    with arcpy.da.SearchCursor(inFC, (field),sWhere,sql_clause=('DISTINCT','ORDER BY FIELDNAME')) as cursor:
        arcpy.AddMessage("Processing data")
        for row in cursor:

            s = s + str(int(row[0]))+ ","
               
    #get Assets list as output
    arcpy.SetParameterAsText(3, s)
    #print arcpy.AddMessage(s)
   
except:
    arcpy.AddMessage(arcpy.GetMessages())
finally:
    arcpy.AddMessage("Process complete")

 

I have run the script as a script tool, generated the result and published the result to ArcGIS for Server 10.2.

 

I can consume this GP service from my web app without any problems and return the values as I expect, however after a few hours the GP service will start to return the default result i.e. the result obtained when I published the GP service regardless of what parameters I am passing in.

 

The annoying thing is that the GP service is not throwing an error but just returns the default result which will be wrong for the parameters passed in.

 

As you can see in the script above I have put several arcpy.AddMessage statements to try and figure out where the GP service is failing. I run the gp service with the same input values my ArcGIS server services directory and view all the messages and I can report the following. The script is failing on this line i.e. script is not executing the line

 

with arcpy.da.SearchCursor(inFC, (field),sWhere,sql_clause=('DISTINCT','ORDER BY FIELDNAME')) as cursor:

 

as the last message I see is "inside try" and I do not see "Processing data" when the script/gp service is failing.

 

The GP service does not return any errors even though the code is wrapped within a try/catch.

 

The only thing that is curing this problem for me is to restart the GP service which is not ideal in a Production environment. Any suggestions welcome.

Outcomes