Hi,
I have a notebook that runs 5 nights a week after working days. The script takes a copy of a feature layer and exports it as a FileGDB. This generally works, however on occasion, some files will take an excessively long time to export, resulting in the script timing out. I can't for the life of me work out what causes this to happen - the same files that are unchanged from one day to the next can go from taking <1 minute to several times that.
The issue seems similar to this one here: Re: Scheduled Notebook sometimes exceeds execution... - Esri Community
now = datetime.datetime.now()
existing_backups = [item.title for item in user.items(folder='Backups')]
query_string = "tags: 'to_backup'"
feature_services = gis.content.search(
query=query_string,
max_items=-1,
item_type='Feature Service'
)
for fs in feature_services:
print(f'Processing: {fs.title}')
file_name = generate_name(fs.title, now)
if file_name not in existing_backups:
try:
fs.export(file_name, 'File Geodatabase', parameters=None, wait=False, tags='backup')
except:
print(f"Couldn't export {fs.title} - {fs.id}")
export = gis.content.search(file_name, item_type='File Geodatabase')
if export:
try:
fgdb = gis.content.get(export[0].itemid)
fgdb.move("Backups")
print(f'Backup of {fs.title} complete\n')
except:
print(f"Not able to move item: {file_name}, check if item already exists in 'Backup' folder")
else:
print(f"No backups with name {file_name} found")
else:
export = gis.content.search(file_name, item_type='File Geodatabase')
print(f"Backup: {file_name} already exists, skipping to next item\n")
print("Backup processing complete")