Story #3226

Updated by bmbouter over 3 years ago

h2. Motivation

A RepositoryVersion that has complete=False and experiences an error will be deleted by core, then exception will be reraised, and the user will see the exception in the task failure. In the event of a crash though, we have no mechanism to clean up the incomplete RepositoryVersion. This would be an area of improvement.

h2. Design

h4. Storing crash info for cleanup later

The <code>created_resources</code> field stores a reference
Add an attribute to the created <code>RepositoryVersion</code>. Any time a RepositoryVersion called <code>task</code> that is created, it needs to a: <code>ForeignKey('Task', null=True, backref='repo_version')</code>

This attribute <code>task</code>would
be saved as a <code>created_resources</code> object visible in the same transaction. RepositoryVersion serializer
The backref <code>repo_version</code> attribute would *not* be visible on the Task serializer

h4. Cleaning up

Update the "task
Have "the task cleanup code": to delete any <code>task.created_resources.filter(complete=False)</code>

all of the associated repository versions. That worker already holds the necessary locks to make this operation safe so it just needs to make sure to perform the deletions before deleting the corresponding ReservedResource records.

h4. created_resources only show resources with completed=True

A saved reference in <code>created_resources</code> is only visible on the Task's viewset or filterset if completed=True.