Select to view content in your preferred language

ArcGIS Pro Scheduling a Python scripted Portal item update

663
3
10-12-2022 02:43 PM
SamuelMcAuley
New Contributor II

I am not very familiar with Python but am trying to write a script in ArcGIS Pro that will update the offline areas that I have created for a web map that is hosted on our organisation's Enterprise Portal. I have gotten the script to execute perfectly fine when I manually run it in Pro but I want to schedule it to run using Windows Task Scheduler so that these updates can occur outside of work hours.

I set up a schedule however when I checked back later the updates hadn't occurred. There was nothing in the 'History' pane of ArcGIS Pro that suggested the task had even attempted to run (it still said 'Scheduled'). I first thought that this was an issue with Pro being closed and the Portal not being able to be authenticated and so I scheduled the task to run again and left Pro open but the same result happened. Now I am thinking that perhaps it is not an authentication issue but something else altogether.

This is a cut-down version of the script I am trying to run;

from arcgis.gis import GIS
from arcgis.mapping import WebMap
import arcpy

gis = GIS('Pro')


GIS_admin = 'aa7f0378d0bd4c31a1bd18b2dbac1b11'
map_item = gis.content.get('686be07874f946df91d7d72b2f87e347')

map_item.unshare(groups=[GIS_admin])
WebMap(map_item).offline_areas.update()

map_item.share(groups=GIS_admin, allow_members_to_edit=True)
        

I have tried playing around with the settings in Windows Task Scheduler itself to 'Run whether user is logged in or not' without success. If someone has any light that they can shed that would be greatly appreciated. 

0 Kudos
3 Replies
RhettZufelt
MVP Notable Contributor

Have you tried running it manually with IDLE "outside" of Pro?

This might give you some error/messages that could make it easier to debug.

If I had to guess, I'd think it is something to do with setting the GIS to 'Pro', but is not running within pro as the task scheduler will run as stand alone.

suspect it is lookinng for something more like:

gis = GIS("https://portalname.domain.com", "sharinguser", "password")

More here.

R_

SamuelMcAuley
New Contributor II

I have tried running it in a Jupyter Notebook whilst Pro was closed and it worked totally fine. That was using both these parameters:

gis = GIS("home")

 

and

gis = ("Pro")

So not sure if that addresses your point?

 

Thanks 🙂

 

0 Kudos
SamuelMcAuley
New Contributor II

Update: I have discovered the problem. It was nothing to do with the code or the authentication but instead it was to do with the Toolbox in which the script was saved. The toolbox in which it was saved was built in ArcMap and we have since built new toolboxes in ArcGIS Pro. I migrated the script to one of these newer toolboxes and scheduled it and it worked as expected. Perhaps there are some compatibility issues with Toolboxes between ArcMap and Pro. Anyhow, thanks for the input 🙂

0 Kudos