I want to programmatically access the current job id of a geoprocessing script running on ESRI 10.2. The script is what needs to know the job id, not the caller of the script.
While searching, I have seen plenty of examples of how the submit job request returns with the job id. This isn't what I want.
In my script that is running on the server, I want to include the job id in the logs, however I haven't found how to obtain the job in in the script. I initially checked arcpy.env
, but I didn't see anything. Where else should I look?
Answer
I remembered an old script I use in testing so I thought I'd share. Maybe it'll help you or someone else. I added the logic to get the GUID. There's probably a better way to do it, but it works.
import arcpy, sys, socket, os
theExe = sys.executable
arcpy.AddMessage("the executable : " + theExe)
arcpy.AddMessage("where is arcpy : " + str(arcpy.__file__))
arcpy.AddMessage("the install dir : " + str(arcpy.GetInstallInfo()["InstallDir"]))
arcpy.AddMessage("the product is : " + str(arcpy.GetInstallInfo()["ProductName"]))
arcpy.AddMessage("the py version is : " + str(sys.version))
arcpy.AddMessage("hostname : " + str(socket.gethostname()))
arcpy.AddMessage("path : " + str(sys.path[0]))
arcpy.AddMessage("path : " + str(os.path.dirname(__file__)))
arcpy.AddMessage("working dir : " + str(os.getcwd()))
scr = arcpy.env.scratchFolder
arcpy.AddMessage(scr)
if "server" in theExe.lower():
guid = os.path.split(os.path.split(scr)[0])[1] #split 'scratch' off, then split remainder and grab guid
arcpy.AddMessage(guid)
arcpy.AddMessage("--------------------------------")
arcpy.AddMessage(arcpy.ProductInfo())
arcpy.AddMessage(arcpy.GetInstallInfo())
No comments:
Post a Comment