Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolves #459 - Add message to use --ignore-errors with --repeat #460

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,11 @@ epcc runbooks run misc get-store-info

## Development Tips

### Retries vs Ignoring Errors

Retries in epcc-cli will retry the _exact_ rendered request so if you are using templated parameters i.e., `auto-fill` and the failure is deterministic (say a unique constraint),
a retry will just get stuck in a loop. In this case if you want to create many different records, you want to `--ignore-errors`.

### Fast rebuilds

For development the following command using [Reflex](https://github.com/cespare/reflex) can speed up your development time, by recreating the command line tool.
Expand Down
4 changes: 4 additions & 0 deletions cmd/repeater.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"github.com/elasticpath/epcc-cli/external/httpclient"
"github.com/elasticpath/epcc-cli/external/shutdown"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand All @@ -16,6 +17,9 @@ func repeater(c func(*cobra.Command, []string) error, repeat, repeatDelay uint32
if ignoreErrors {
log.Debugf("Ignored error %v", ignoreErrors)
} else {
if repeat > 1 && !ignoreErrors && httpclient.RetryAllErrors {
log.Infof("If you want to continue repeating even if the requests gets a 4xx you should use `--ignore-errors.`")
}
return err
}
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
7 changes: 7 additions & 0 deletions external/httpclient/httpclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions external/runbooks/pxm-how-to.epcc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down
Loading