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:

  1. remove calls to Update inside runImport if there are any errors.

  2. handle error outside ih.runImport and call Update with the correct import status:

    err := ih.runImport(...)
    if err != nil {
      if errors.Is(err, context.Canceled) {
        // create new context
        ih.Update(newCtx)...
      }
    }
  3. remove call to Update inside sendImportNotification per !948 (comment 894236335)

Edited by Jaime Martinez