Implement Import DELETE route
Context
This endpoint would serve to stop and abandon an in-progress import or pre import,
Proposal
We need to write a special canceled status to the migration status in the DELETE handler and look for this status at the end of an import and rollback the import. This is a little inelegant since we only check at the end of an import or pre import to invalidate the result. For imports, this is acceptable, but for pre imports, this is essentially useless since we don't use transactions there.
What we could do is periodically check (with a ticker, or after importing N manifests) for a change in the status and abort the (pre)import at that point.
I think setting up a ticker that cancels the context if the migration status is import_canceled is probably the most consistent, as the length of time between checks won't be affected by how many references each manifest has. We'll only need to set it up in a single place, in the handler.
The ticker is simpler and elegant, but probably more prone to failures. I think we can start with that and make sure we have good logging/metrics around it.
In regards to import_canceled vs import_failed, I think it would make sense to reserve import_failed for unexpected failures, which is not the case for a cancelation.
Route
DELETE gitlab/v1/import/<name>
Add a special ?force=true -> in case of an emergency. This will trigger a soft delete that will mark an import as import_failed.
Success
-
202 AcceptedThe repository was found and the ongoing (pre)import will be canceled. An async notification will be sent once the cancelation occurs.
Errors
-
400 Bad RequestThe repository was found, but there is no ongoing (pre)import to cancel. -
401 UnauthorizedThe client should take action based on the contents of theWWW-Authenticateheader and try the endpoint again. -
404 Not FoundThe repository was not found.