From e3eb73baa3cdbe66d5821a8b24f1fb0d5947a6d0 Mon Sep 17 00:00:00 2001 From: Steve Ramage Date: Sat, 10 Aug 2024 15:48:16 -0700 Subject: [PATCH] WIP #459 --- cmd/root.go | 3 ++- external/httpclient/httpclient.go | 7 +++++++ external/runbooks/pxm-how-to.epcc.yml | 4 ++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 406c87e..88da130 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -126,7 +126,8 @@ func InitializeCmd() { RootCmd.PersistentFlags().BoolVarP(&httpclient.Retry429, "retry-429", "", false, "Whether we should retry requests with HTTP 429 response code") RootCmd.PersistentFlags().BoolVarP(&httpclient.RetryConnectionErrors, "retry-connection-errors", "", false, "Whether we should retry requests with connection errors") RootCmd.PersistentFlags().UintVarP(&httpclient.RetryDelay, "retry-delay", "", 500, "When retrying how long should we delay") - RootCmd.PersistentFlags().BoolVarP(&httpclient.RetryAllErrors, "retry-all-errors", "", false, "When enable retries on all errors (i.e., the same as --retry-5xx --retry-429 and --retry-connection-errors") + RootCmd.PersistentFlags().BoolVarP(&httpclient.RetryAllErrors, "retry-all-errors", "", false, "When enable retries on all errors (i.e., the same as --retry-5xx, --retry-4xx and --retry-connection-errors") + RootCmd.PersistentFlags().BoolVarP(&httpclient.RetryTemporaryErrors, "retry-temporary-errors", "", false, "When enable retries on all errors (i.e., the same as --retry-5xx --retry-429 and --retry-connection-errors") RootCmd.PersistentFlags().BoolVarP(&httpclient.DontLog2xxs, "silence-2xx", "", false, "Whether we should silence HTTP 2xx response code logging") diff --git a/external/httpclient/httpclient.go b/external/httpclient/httpclient.go index aa8d85e..a9730f2 100644 --- a/external/httpclient/httpclient.go +++ b/external/httpclient/httpclient.go @@ -122,6 +122,9 @@ var Retry5xx = false var RetryConnectionErrors = false var RetryAllErrors = false +var RetryTemporaryErrors = false +var Retry422 = false + var RetryDelay uint = 500 var statsLock = &sync.Mutex{} @@ -378,6 +381,10 @@ func doRequestInternal(ctx context.Context, method string, contentType string, p displayLongFormRequestAndResponse = false } + if resp.StatusCode == 422 && Retry422 { + displayLongFormRequestAndResponse = false + } + if resp.StatusCode >= 500 && Retry5xx { displayLongFormRequestAndResponse = false } diff --git a/external/runbooks/pxm-how-to.epcc.yml b/external/runbooks/pxm-how-to.epcc.yml index ff357ca..de03adc 100644 --- a/external/runbooks/pxm-how-to.epcc.yml +++ b/external/runbooks/pxm-how-to.epcc.yml @@ -25,7 +25,7 @@ actions: epcc create pcm-product-price name=Preferred_Pricing currencies.USD.amount 300000 currencies.USD.includes_tax false currencies.GBP.amount 250000 currencies.GBP.includes_tax false sku BE-Electric-Range-1a1a epcc create pcm-product-price name=Preferred_Pricing currencies.USD.amount 350000 currencies.USD.includes_tax false currencies.GBP.amount 300000 currencies.GBP.includes_tax false sku BE-Gas-Range-2b2b - epcc create pcm-catalog name "Ranges Catalog" description "Ranges Catalog" pricebook_id name=Preferred_Pricing hierarchy_ids[0] name=Major_Appliances - - epcc create pcm-catalog-release --save-as-alias pxm-how-to-create-catalog-and-publish-release name=Ranges_Catalog + - epcc create pcm-catalog-release --retry-while-jq '.errors[0].status == 422' --save-as-alias pxm-how-to-create-catalog-and-publish-release name=Ranges_Catalog # Wait for Catalog to be Published - epcc get pcm-catalog-release --retry-while-jq '.data.meta.release_status != "PUBLISHED"' name=Ranges_Catalog pxm-how-to-create-catalog-and-publish-release create-catalog-rule: @@ -105,7 +105,7 @@ actions: - epcc create pcm-product attributes.name "SKU-less Bed and Ball Bundle" attributes.commodity_type "physical" status "live" components.dogbed.max 1 components.dogbed.min 1 components.dogbed.name "Dog Bed" components.dogbed.options[0].id alias/product/name=Fluffy_Bed/id components.dogbed.options[0].type "product" components.dogbed.options[0].quantity 1 components.dogball.max 1 components.dogball.min 1 components.dogball.name "Dog Ball" components.dogball.options[0].id alias/product/name=Squeaky_Ball/id components.dogball.options[0].type "product" components.dogball.options[0].quantity 1 - epcc create pcm-node-product name=Pet_Supplies name=Dog_Supplies data[0].type product data[0].id name=SKU-less_Bed_and_Ball_Bundle - epcc create pcm-catalog name "Pet Supplies Catalog" description "Pet Supplies Catalog" pricebook_id name=VIP_Pricing hierarchy_ids[0] name=Pet_Supplies - - epcc create pcm-catalog-release name=Pet_Supplies_Catalog --save-as-alias pxm-how-to-publish-catalog-with-bundles-release + - epcc create pcm-catalog-release --retry-while-jq '.errors[0].status == 422' name=Pet_Supplies_Catalog --save-as-alias pxm-how-to-publish-catalog-with-bundles-release # Wait for Catalog to be Published - epcc get pcm-catalog-release --retry-while-jq '.data.meta.release_status != "PUBLISHED"' name=Pet_Supplies_Catalog pxm-how-to-publish-catalog-with-bundles-release