From 98e00bdb5824c6d05df3c8cadee8598ea361cd54 Mon Sep 17 00:00:00 2001 From: Benoit Socias Date: Thu, 19 May 2022 07:51:05 +0000 Subject: [PATCH] [FIX] website: allow retrying if website configurator fails Whenever an error happens during the website creation after the last step of the website configurator, it is displayed as an notification popup, but it keeps the UI blocked, preventing the user from retrying the operation. The usually observed error is about not being able to install the module or theme because a cron is in progress. The message actually asks the user to retry later. This commit does the following upon errors happening during the website creation: - silently retry after 5 seconds, up to 3 times - after all attempts failed, display the error and release the UI and allow for manual retry. task-2809434 closes odoo/odoo#98124 X-original-commit: 2afdbc7181de3c87c1021f1e06d059ffe059ede0 Signed-off-by: Romain Derie (rde) Signed-off-by: Benoit Socias (bso) --- .../configurator/configurator.js | 44 +++++++++++++------ 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/addons/website/static/src/client_actions/configurator/configurator.js b/addons/website/static/src/client_actions/configurator/configurator.js index 7498c85f974..4e1ce657e11 100644 --- a/addons/website/static/src/client_actions/configurator/configurator.js +++ b/addons/website/static/src/client_actions/configurator/configurator.js @@ -1,5 +1,6 @@ /** @odoo-module **/ +import concurrency from 'web.concurrency'; import utils from 'web.utils'; import weUtils from 'web_editor.utils'; import {ColorpickerWidget} from 'web.Colorpicker'; @@ -356,6 +357,23 @@ class ApplyConfiguratorScreen extends Component { if (!this.state.selectedPalette) { return this.props.navigate(ROUTES.paletteSelectionScreen); } + + const attemptConfiguratorApply = async (data, retryCount = 0) => { + try { + return await this.orm.silent.call('website', + 'configurator_apply', [], data + ); + } catch (error) { + // Wait a bit before retrying or allowing manual retry. + await concurrency.delay(5000); + if (retryCount < 3) { + return attemptConfiguratorApply(data, retryCount + 1); + } + document.querySelector('.o_website_loader_container').remove(); + throw error; + } + }; + if (themeName !== undefined) { this.websiteService.showLoader({ showTips: true }); const selectedFeatures = Object.values(this.state.features).filter((feature) => feature.selected).map((feature) => feature.id); @@ -370,20 +388,18 @@ class ApplyConfiguratorScreen extends Component { ]; } - const resp = await this.orm.silent.call('website', - 'configurator_apply', - [], - { - 'selected_features': selectedFeatures, - 'industry_id': this.state.selectedIndustry.id, - 'selected_palette': selectedPalette, - 'theme_name': themeName, - 'website_purpose': WEBSITE_PURPOSES[ - this.state.selectedPurpose || this.state.formerSelectedPurpose - ].name, - 'website_type': WEBSITE_TYPES[this.state.selectedType].name, - 'logo_attachment_id': this.state.logoAttachmentId, - }); + const data = { + 'selected_features': selectedFeatures, + 'industry_id': this.state.selectedIndustry.id, + 'selected_palette': selectedPalette, + 'theme_name': themeName, + 'website_purpose': WEBSITE_PURPOSES[ + this.state.selectedPurpose || this.state.formerSelectedPurpose + ].name, + 'website_type': WEBSITE_TYPES[this.state.selectedType].name, + 'logo_attachment_id': this.state.logoAttachmentId, + }; + const resp = await attemptConfiguratorApply(data); this.props.clearStorage();