refactor(handlers): allow to update dbRepo when the (pre)import has been canceled/failed
Context
When an import has been canceled by the DELETE method, the ongoing (pre)import context's cancel function is called, triggering a context.Canceled error inside the ih.runImport(importCtx ...) function after importer.PreImport or importer.Import. We use the same importCtx to call the ih.Update(importCtx ...) function, which is already canceled, so the update operation fails.
See !948 (comment 894236335) for additional details.
Solution
We should refactor the ih.runImport function so that we handle the context.Canceled error correctly:
-
remove calls to
UpdateinsiderunImportif there are any errors. -
handle error outside
ih.runImportand callUpdatewith the correct import status:err := ih.runImport(...) if err != nil { if errors.Is(err, context.Canceled) { // create new context ih.Update(newCtx)... } } -
remove call to
UpdateinsidesendImportNotificationper !948 (comment 894236335)