retry dictionary registration#201
Conversation
| 409: | ||
| $ref: '#/components/responses/StatusConflict' |
There was a problem hiding this comment.
if registering the same Dictionary for the category then it throws a 409 error, unless the "force" flag is true.
| - name: force | ||
| description: Re-registers the current active dictionary on the category and retries the data migration. | ||
| in: query | ||
| required: false | ||
| schema: | ||
| type: boolean | ||
| default: false |
There was a problem hiding this comment.
Can you add more detail about this behaviour? I don't know what re-registering a dictionary will do. Is this the same as initiating a migration? If the dictionary version is the same as the current dictionary will it run the migration with the intention of revalidating the data (should have no impact on the current data state)?
|
|
||
| If a category is already using the same dictionary name and version, registration returns `409 Conflict`. | ||
|
|
||
| Set the `force` query parameter to `true` to allow re-registration and trigger a migration (or retry) to revalidate existing category data against that dictionary. |
There was a problem hiding this comment.
Repeating my comment since this is the full documentation about registering dictionaries:
Can you add more detail about this behaviour? I don't know what re-registering a dictionary will do. Is this the same as initiating a migration? If the dictionary version is the same as the current dictionary will it run the migration with the intention of revalidating the data (should have no impact on the current data state)?
| const newMigration: NewDictionaryMigration = { | ||
| categoryId, | ||
| fromDictionaryId, | ||
| fromDictionaryId: fromDictionaryId ?? toDictionaryId, |
There was a problem hiding this comment.
This is confusing to read - perhaps we should leave it as required and the caller can indicate that fromDictionaryId value should be the same value as toDictionaryId. I would not expect the migration service to assume that if from value is not provided you reuse the to value.
| if (forceRegistration) { | ||
| logger.info( | ||
| LOG_MODULE, | ||
| `Force flag is true, initiating migration for Category '${foundCategory.name}' | ||
| with Dictionary '${savedDictionary.name}' version '${savedDictionary.version}'`, | ||
| ); | ||
|
|
||
| const resultMigration = await initiateMigration({ | ||
| categoryId: foundCategory.id, | ||
| toDictionaryId: savedDictionary.id, | ||
| userName: username || '', | ||
| }); | ||
|
|
||
| if (!resultMigration.success) { | ||
| const errorMessage = `Failed to initiate migration for category '${categoryName}' with error: ${resultMigration.data}`; | ||
| logger.error(LOG_MODULE, errorMessage); | ||
| throw new Error(errorMessage); | ||
| } | ||
|
|
||
| return { dictionary: savedDictionary, category: foundCategory, migrationId: resultMigration.data }; | ||
| } | ||
|
|
||
| throw new StatusConflict( | ||
| `Category '${categoryName}' with Dictionary '${savedDictionary.name}' version '${savedDictionary.version}' already exists`, | ||
| ); |
There was a problem hiding this comment.
This is not very DRY, a lot of repeated code from the else block. The only difference is omitting the fromDictionaryId and changed log statements. Is there a way to write this that won't open us up to a future code change that is only made in one branch of this if statement?
Description
It enables the possibility to retry "failed" Dictionary migration by adding a
forceflag on the Dictionary Registration endpoint.Details:
POST /dictionary/registerendpoint to accept an optional query paramforceto Re-register the current active dictionary on the category and retries the data migration.Related tickets:
This PR depends on: