Running python script with windows task scheduler and ArcGIS Server python environment

316
4
08-06-2022 02:46 PM
ChaimSchwartzIroads
New Contributor II

Background technical info:  We have a 10.6 or 10.9.1 ArcGIS Enterprise Installation (we are in the process of migrating so I have both available), IWA, and a requirement to use gMSA accounts to run the arcgis server windows service. Our arcgis pro licenses are managed by named users through arcgis online. 

I'm trying to understand if there's a way to run a scheduled script using windows task manager, without the need of an arcgis pro license. It seems like standard documentation online requires pointing to the arcgis pro-environment: 

"C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe"

However, this requires (1) installing arcgis pro on our production server (2) running the windows task as a user that has also logged in to arcgis pro with a valid license (named user via arcgis online). I prefer not to go down that road since I don't want to use one of our arcgis pro licenses on this user. 

So, we moved to using the arcgis server's python environment instead:

"C:\Program Files\ArcGIS\Server\framework\runtime\ArcGIS\bin\Python\envs\arcgispro-py3\python.exe"

However I'm finding no documentation to support this workflow. Also, it seems like going down this path only works if I run the task as the same gMSA user that runs the arcgis server windows service. Can any body confirm this??

 

0 Kudos
4 Replies
jcarlson
MVP Notable Contributor

I would use a python environment manager like conda to create a separate environment for running automated scripts. Then you can have a .bat script that calls conda, activates the particular environment you need, and runs your script.

We have about half a dozen scripts that run this way every night, and we can literally use those same scripts on any machine. You'll want to look at authentication strategies with the Python API. There's even one designed to work with IWA, though I've not used it myself.

- Josh Carlson
Kendall County GIS
0 Kudos
ChaimSchwartzIroads
New Contributor II

Thank you Josh - even with a different environment I'd be facing the same question - which user do I need the task to run with, in order to be able to run python api? 

0 Kudos
jcarlson
MVP Notable Contributor

Well, it depends on what you're doing with the script. You can authenticate with the API using a named user, and the script would then have access to anything that user does. So an anonymous user could access any public layers and apps, but be unable to change anything, whereas an admin would be able to access and edit anything.

- Josh Carlson
Kendall County GIS
0 Kudos
ChaimSchwartzIroads
New Contributor II

Hi Josh, perhaps I wasn't being clear: my question is in regards to the user that the task is run as in windows task manager (not the arcgis user to connect to the portal). Windows task manager requires running the task as an admin user in order to be able to run the task whether the user is logged in or not. 

0 Kudos