How to automate the workforce scripts with Windows Scheduler

3558
19
Jump to solution
11-20-2018 12:50 PM
LaneHartman
New Contributor III

I'm looking for some guidance on modifying the assignment workforce scripts so I can use them with the windows scheduler and have them run in the background.  The scripts work great when I run them from the Python Command Prompt, but I'm not sure how to switch to Windows Scheduler automation. Just running the script as is in WinSch doesn't seem to work. Craig GillgrassAaron Pulver

Thanks

0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

What types of errors or logs are generated. You need to make sure that the script is using the correct python interpreter.

This is what my test task looks like (Windows Server 2016):

Make sure you are running with a user that has the correct permissions (depends what you want to do).

Make sure you set the full path to the python environment that has the ArcGIS API for Python installed in my case this is "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe"

Make sure you add an argument with the full path to the script you want to run. In my case this is "C:\Users\<my-username>\some_script.py". Add any other arguments your script by expect.

I would test that the task can be run manually from within the Task Scheduler. Then if that's working, add a trigger to schedule it.

Hope that helps,

Aaron

View solution in original post

0 Kudos
19 Replies
GeorgeKatsambas
Occasional Contributor III

I am having the same problem since switching to window 10, task scheduler wont schedule a python script either, some sort of security I believe. hope someone can answer also.

0 Kudos
by Anonymous User
Not applicable

What types of errors or logs are generated. You need to make sure that the script is using the correct python interpreter.

This is what my test task looks like (Windows Server 2016):

Make sure you are running with a user that has the correct permissions (depends what you want to do).

Make sure you set the full path to the python environment that has the ArcGIS API for Python installed in my case this is "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe"

Make sure you add an argument with the full path to the script you want to run. In my case this is "C:\Users\<my-username>\some_script.py". Add any other arguments your script by expect.

I would test that the task can be run manually from within the Task Scheduler. Then if that's working, add a trigger to schedule it.

Hope that helps,

Aaron

0 Kudos
LaneHartman
New Contributor III

Aaron,

Thanks, I think this will work. The python environment paths were where I was hung up on. I'll let you know what I find.

0 Kudos
LaneHartman
New Contributor III

Aaron,

The create assignments by csv script works great using this method, but I can't get the assignment monitor script to work using the the same method.  Does this have something to do with the loop that script has in it?

0 Kudos
by Anonymous User
Not applicable

Yeah that script was mostly for a demo. You have to modify it to remove the loop (since you will schedule it to run every 1 minute or whatever).

0 Kudos
LaneHartman
New Contributor III

Ok, this modification of the assignment_monitor.py script runs fine from the command prompt without looping, but I still can't get it to work from Windows Scheduler.  What am I missing here?

0 Kudos
by Anonymous User
Not applicable

My hunch is that you need to define the full path to the config file on line 149:

config.read("config.ini")

Windows Task Scheduler may be running the script from another directory so it might not find that file.

0 Kudos
LaneHartman
New Contributor III

Defining the full path to the config.ini file didn't seem to do anything.  I did notice that it's not writing anything to the log file either when I attempt to run the script from Windows Scheduler. I've attached screenshots of the Windows Scheduler tabs in case there is an issue there. It is set up like the create_assignments_from_csv.py script (which works well from Windows Scheduler) without the additional arguments that that script requires.  Are there some additional arguments besides the script file and path to it?

0 Kudos
daveostrander
Occasional Contributor II

Hi Aaron,

How would the arguments look in the Task Scheduler? I am used to running batch files that call python and list the arguments directly in the batch, but just opening cmd and running the example code isn't working for me. The scripts only appear to work when running in the Anaconda Prompt. Since the script works just fine when running it manually, I guess I need to open the Anaconda Prompt within Task Scheduler, but then just need direction on how to add the following arguments.

-u username -p password -org "https://<org>.maps.arcgis.com" -project-id "038a1926d2d741dc8acabefd5b2cc5d3" -log-file "../log.txt" -where "1=1"

I am including the full path to the script as the first parameter as you advised, but not sure how the quotes affect task scheduler. So far I am loading them into the argument text box exactly as the example shows in the line above/on your Git site.

Any help would be appreciated.

0 Kudos