The cleanup service deletes Archived Tasks, and their associated model checkpoints (snapshots), other artifacts, and debug samples. You configure it with parameters specifying which Archived Tasks to delete and when to delete them. Its Task name is
Cleanup Service and it is associated with the project
You can configure the
Cleanup Service in the Trains Web (UI), and then enqueue the Task to execute in Trains services mode. It is pre-loaded in Trains Server and its status is Draft (editable). Or, run the script cleanup_service.py, with options to run locally or as a service.
Running the cleanup service
Running using the Trains Web (UI)
Step 1. Configuring the cleanup service
- In the Trains Web (UI) Projects page, click the DevOps project > click the Cleanup Service Task.
- In the info panel, click the CONFIGURATION tab.
- In the GENERAL section, hover over the parameter area > EDIT.
- Configure the service parameters:
- cleanup_period_in_days - Repeat the cleanup service at this interval, in days. The default value is 1.0 (run once a day).
- delete_threshold_days - Tasks older than this number of days will be deleted. The default value is 30 days.
- True - Delete all Tasks older than delete_threshold_days.
- False - Delete only status created (Draft) Tasks. The default value is False.
- True - Run the cleanup as a service (it repeats regularly).
- False - Run the Task once locally. The default value False.
Step 2. Enqueuing the cleanup service
- Right click the Cleanup Service Task > Enqueue > In the queue list, select services > ENQUEUE.
Running using the script
The cleanup_service.py allows you to enqueue the cleanup service to run in Trains Agent services mode, because the
run_as_service parameter is set to
The cleanup service code
cleanup_service.py creates a Trains API client session to delete the Tasks. It creates an
APIClient object which establishes a session with the Trains backend (Trains Server), and accomplishes the cleanup by calling:
Tasks.get_allto get a list of Tasks to delete, providing the following parameters:
system_tags- Get only Tasks tagged as
only_fields- Get only the Task
id. Only the Task
idis needed to delete Tasks and its output.
order_by- Order the list of Tasks returned by last activity timestamp, in descending order (most recent first).
page_size- Set the number of Tasks returned in each page (the last page may contain fewer results).
page- Set the number of the page in the resulting list of Tasks to return.
status_changed- Get Tasks whose last status change is older than then delete threshold (in seconds).
Tasks.delete- Delete a Task, optionally forcing the deletion of a Task, even if its status is not Draft.