Select to view content in your preferred language

Cleaning up completed jobs

225
3
07-17-2025 06:48 AM
ChrisBerryman
Regular Contributor

Is it possible to cleanup completed jobs without manually deleting jobs?   It would be nice to do a clean up and only retain x amount of days of completed jobs. 

Would python be suitable for it?

0 Kudos
3 Replies
CodyPatterson
MVP Regular Contributor

Hey @ChrisBerryman 

You can setup a Python script to have a date cutoff and delete certain jobs after a certain date threshold, I do this currently with Workforce points, but it may also be a good idea to move them to a separate backup table instead of fully deleting for record keeping purposes.

If you'd like a good structure on how to create this script let me know and I'll post one!

Cody

ChrisBerryman
Regular Contributor

Yeah if you got an example that would be great! 

Thank you!

 

0 Kudos
CodyPatterson
MVP Regular Contributor

Hey @ChrisBerryman 

Here's an example of the deletion process:

from arcgis.gis import GIS
from dotenv import load_dotenv
from datetime import datetime, timedelta
load_dotenv()

gis = GIS('https://<company>.com/portal', username, password)

# Workforce Assignments

wforce = 'id'
WFwforce = gis.content.get(wforce)
WFwforceLayers = WFwforce.layers
wforceLayer = WFwforceLayers[0]
wforce_features = wforceLayer.query().features

yesterday = datetime.now() - timedelta(days=1)
yesterday_hour = yesterday.replace(minute=0, second=0, microsecond=0)
unix_yesterday = int(yesterday_hour.timestamp())

for item in wforce_features:
    item_attr = item.attributes
    if item_attr['completeddate'] != None:
        if item_attr['completeddate'] > unix_yesterday:
            # Delete the item

Cody

0 Kudos