GP Service Multiple Processes from MXD

1612
12
03-09-2017 08:43 AM
LloydBronn
Occasional Contributor II

I have a GP service that generates a PDF report for a country based on a click event. This report includes charts generated on the fly with matplotlib, sourced from rasters. It also includes symbolized raster images exported from an MXD. While testing, we've found that if two users try to run the service at the same time, it errors out for both users. The browser console.log displays: "unable to complete operation."  The ArcGIS server logs displays: " MapDocObject: Unable to save. Check to make sure you have write access to the specified file and that there is enough space on the storage device to hold your document. Failed to execute." We don't get these errors when we run the process one at a time.I'm assuming that the MXD can only be accessed by one user at a time. Is there a way for the server to queue users if more than one are trying to access this process at the same time? Would saving multiple numbered copies of the MXD solve the problem?

0 Kudos
12 Replies
LloydBronn
Occasional Contributor II

OK, so when I call update_background_layers(newMXD,df,input_country) I get a server error:

arcpy.mapping.MapDocument("C:\\Website_Test\\Report_Tests\\MXDs\\Analysis_For_Reports.mxd") File "c:\program files\arcgis\server\arcpy\arcpy\arcobjects\mixins.py", line 611, in __init__ assert (os.path.isfile(mxd) or (mxd.lower() == "current")), gp.getIDMessage(89004, "Invalid MXD filename") AssertionError: Invalid MXD filename. Failed to execute (CreateReport). Failed to execute (CreateReport).

0 Kudos
KevinHibma
Esri Regular Contributor

That'll be from MY line #22 above. It sounds like for some reason it couldnt find the new MXD it saved. If this is coming from the service you'll need to manually inspect those directories and make sure something got created in the scratch directory. You may also need to add some AddMessages to see whats going where. Sorry, the code above is untested, but fundamentally I'm sure of what needs to happen/flow.

LloydBronn
Occasional Contributor II

All the directories, data and MXD are local on the Server C drive. I had problems with the paths to the server system folder before, so I made everything local. Here is the definition. I confirmed that the MXD is copying to the RAM drive temp folder, but it still errors out when we try to make two reports simultaneously. I'm a little mixed up, should I pass in newMXD instead of mxd in the function call?

def update_background_layers(mxd,df,input_country):
 
 background_layers_list = ["cities", "country", "oceanout","whiteout", "six_largest_cities"]
for background_layer in background_layers_list:
 
 for lyr in arcpy.mapping.ListLayers(mxd):
 if lyr.supports("DATASOURCE"):
 
 if background_layer == str(lyr.name):
 old_source = os.path.dirname(lyr.dataSource)
 new_source = "C:\\Website_Test\\Report_Tests\\Background_Layers\\" + input_country
 
 lyr.findAndReplaceWorkspacePath(old_source, new_source, False)

 #mxd.save()
 tempMXD = os.path.join("R:\\temp", "Analysis_For_Reports.mxd")
 mxd.saveACopy(tempMXD)
 # re-load that MXD up as a true MXD object, not just the path
 # because the next function wants the object
 newMXD = arcpy.mapping.MapDocument(tempMXD)
 return newMXD


update_background_layers(mxd,df,input_country)
0 Kudos