Python Script Task Scheduler Alternative

4589
9
Jump to solution
12-17-2018 09:34 AM
deleted-user-RAnIQZ9vH9z7
New Contributor II

I have a python script that I would like execute on an interval of every 5 minutes to check a SDE field for a new record.

Our Enterprise Systems team does not allow Windows Task Scheduler to execute Python. Does anyone know an alternative way to have the script executed?

Currently running ArcGIS 10.5.1 on Windows and SQL Server 2014.

Here is what the script does:

  1. Connect to SDE
  2. Start the arcpy.da.Editor session
  3. Open a arcpy.da.UpdateCursor session
  4. Look for null values and if there is a null, update it a string value
  5. Close the arcpy.da.Editor sesion

The script needs to be run on a server and we are not allowed to use Service Accounts with passwords. We only have Group Managed Service Accounts (gMSA) with no passwords and those are not allowed to execute the python exe.

0 Kudos
1 Solution

Accepted Solutions
deleted-user-RAnIQZ9vH9z7
New Contributor II

Found the work around. The original ArcGIS blog post says to run the Python exe and in the argument, put the location of the .py file. The Enterprise Systems team says no exe files are allowed to run under the Service Account (gMSA). I rewrote my script to execute as a standalone file. Meaning if python is installed on your machine and you double click the .py file, the script should run without calling an exe. This is Vanilla Python and nicely explained by this video.

With my .py file ready to roll, I scheduled a task on the server to call the .py file and not exe. In the Triggers tab, I was able to schedule a Daily task to run at a specific time. My original requirement was every 5 minutes. The Advanced Settings for the Daily task does not work. The work around I have is set a new trigger every 2 hours instead of every 5 minutes and have the customer accept the solution that the Enterprise Systems team has allowed us to work with. Even that, I will have to schedule 12 separate triggers for the 1 task scheduler.

Either case, thanks for all your comments and suggestions!

View solution in original post

9 Replies
MichaelVolz
Esteemed Contributor

Are you not allowed to run any python script thru Windows Task Scheduler or just scripts that would edit the SDE database?  This is not as efficient a process, but you could write the data out to a file geodatabase to check for Nulls and then have an SDE editor perform the edits that are needed.

0 Kudos
deleted-user-RAnIQZ9vH9z7
New Contributor II

Not allowed to run any python script through Windows Task Scheduler. 

0 Kudos
DarrenWiens2
MVP Honored Contributor

There are any number of bad ways to make this happen, but the best option is to have an awkward conversation with your Enterprise Systems team explaining why you need to run Python through task scheduler, or provide their own workaround that will work in your system.

Lake_Worth_BeachAdmin
Occasional Contributor III

well if the team blocks .py file types from running just create a .bat that points to the .py... tasks scheduler runs the batch file, which in returns runs the python file.

EricaPfister
New Contributor III

If the service account running the batch file doesn't have permissions to execute Python, will this method still work?

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Since this is an enterprise geodatabase, I would look into having DBAs create a database trigger to address your NULL to value conversion rather than having ArcPy connect every five minutes, especially in this case since your IT department seems to be making it very difficult for you to run a script.

deleted-user-RAnIQZ9vH9z7
New Contributor II

We're having to go that kind of route. Seems SQL Server Manager can invoke a Job at certain time intervals using the SQL Server Agent. Not sure about SQL Server 2014 though, still researching that. I've asked multiple SQL gurus about addressing the NULL to value conversion and every time I mention that the NULL value needs to be a string, they have no answer. 

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

A quick Google search on "sql server trigger convert null to value" returns several suggestions on how to structure a trigger to do what you want.  In this case, the twist would be that you want it against a view (the versioned view corresponding to the feature class) instead of the base table itself.

0 Kudos
deleted-user-RAnIQZ9vH9z7
New Contributor II

Found the work around. The original ArcGIS blog post says to run the Python exe and in the argument, put the location of the .py file. The Enterprise Systems team says no exe files are allowed to run under the Service Account (gMSA). I rewrote my script to execute as a standalone file. Meaning if python is installed on your machine and you double click the .py file, the script should run without calling an exe. This is Vanilla Python and nicely explained by this video.

With my .py file ready to roll, I scheduled a task on the server to call the .py file and not exe. In the Triggers tab, I was able to schedule a Daily task to run at a specific time. My original requirement was every 5 minutes. The Advanced Settings for the Daily task does not work. The work around I have is set a new trigger every 2 hours instead of every 5 minutes and have the customer accept the solution that the Enterprise Systems team has allowed us to work with. Even that, I will have to schedule 12 separate triggers for the 1 task scheduler.

Either case, thanks for all your comments and suggestions!