Geoprocessing Service Won't Write to Hosted Feature Service

263
0
07-25-2023 11:53 AM
Labels (1)
GregoryWhitaker
New Contributor II

Hello,

Having an issue this week where a GP service that has been published to our server doesn't fail, but also does not produce any results.

An overview of the use case is this: I have a Dirty Areas feature service that contains different error types within a utility network that I am attempting to summarize daily (so that I can create a time series).  I created a hosted table in our portal in which to write a single row each day that contains a simple count, and previous count, of the errors in the former table.

I successfully ran my custom python tool in ArcGIS Pro using both features and it works fine that way--it adds one record to my hosted summary table. However, when publishing the same as a web tool/gp service, it appears to be accessing both tables based on the logging that I added, but upon completion, there is no new record added to the summary table.

In the publish configuration, i set the tool to register the participating layers (not copy) and also ensured that the hosted summary table is editable. My guess is that I'm missing something small but can't think of what else. 

Using Pro v2.9.9, Enterprise 10.9.1

I'm stumped would be grateful for any ideas that might come my way. Tool code is posted below.

import arcpy
from datetime import date

today = date.today()

# these are the dirty areas, validation errors tables
readTable = arcpy.GetParameterAsText(0)
arcpy.AddMessage(f'readTable = {readTable}')
# this is the summary table written to daily
writeTable = arcpy.GetParameterAsText(1)
arcpy.AddMessage(f'writeTable = {writeTable}')

# first, we need to get the previous day's error count from the summary table
# do this by putting summary values in a dict and finding the max() key, return value
# NOTE: tried selecting by attribute using a sql subquery, but query broke once added to a gp tool. 
# DISAMBIGUATION: yesterday's CURRENT_COUNT becomes today's PREVIOUS_COUNT

# initialize dictionary
tableDict = {}
with arcpy.da.SearchCursor(writeTable, ['objectid', 'current_count']) as cursor:
    for row in cursor:
        tableDict[row[0]] = row[1]

arcpy.AddMessage(f'tableDict = {tableDict}')

# use the max key to retrieve the latest value
previousCount = tableDict[max(tableDict)]
arcpy.AddMessage(f'previousCount = {previousCount}, type = {type(previousCount)}')

# then, we store today's error count in memory
currentCount = int(arcpy.management.GetCount(readTable)[0])
arcpy.AddMessage(f'currentCount = {currentCount}, type = {type(currentCount)}')

# fields, values to be inserted in new row
fields = ['current_count', 'previous_count','date', 'date_string']
values = (currentCount, previousCount, today, str(today))

# finally, insert the new record
with arcpy.da.InsertCursor(writeTable, fields) as cursor:
    cursor.insertRow(values)
    arcpy.AddMessage('cursor wrote to summaryTable_test')

 

 

0 Replies