@@ -42,24 +42,31 @@ func getTemplate(db *gorm.DB, accountID int, environments []string) (*int64, err
4242 return templateID , nil
4343}
4444
45- func callCandlepinEnvironment (ctx context.Context , consumer string ) (
46- * candlepin.ConsumersDetailResponse , error ) {
45+ func httpCallCandlepinEnv (ctx context.Context , consumer string ) (interface {}, * http.Response , error ) {
4746 candlepinEnvConsumersURL := utils .CoreCfg .CandlepinAddress + "/consumers/" + consumer
48- candlepinFunc := func () (interface {}, * http.Response , error ) {
49- candlepinResp := candlepin.ConsumersDetailResponse {}
50- resp , err := candlepinClient .Request (& ctx , http .MethodGet , candlepinEnvConsumersURL , nil , & candlepinResp )
51- statusCode := utils .TryGetStatusCode (resp )
52- utils .LogDebug ("candlepin_url" , candlepinEnvConsumersURL , "status_code" , statusCode , "err" , err )
53- if err != nil {
54- err = errors .Wrap (candlepin .ErrCandlepin , err .Error ())
55- } else if statusCode != http .StatusOK && statusCode != http .StatusNoContent {
56- err = errors .Errorf ("candlepin API status %d" , statusCode )
57- }
58- return & candlepinResp , resp , err
47+ candlepinResp := candlepin.ConsumersDetailResponse {}
48+ resp , err := candlepinClient .Request (& ctx , http .MethodGet , candlepinEnvConsumersURL , nil , & candlepinResp )
49+ if err != nil {
50+ utils .LogDebug ("candlepin_url" , candlepinEnvConsumersURL , "err" , err )
51+ return nil , resp , errors .Wrap (candlepin .ErrCandlepin , err .Error ())
52+ }
53+ statusCode := utils .TryGetStatusCode (resp )
54+ utils .LogDebug ("candlepin_url" , candlepinEnvConsumersURL , "status_code" , statusCode )
55+ if statusCode != http .StatusOK && statusCode != http .StatusNoContent {
56+ err = errors .Errorf ("candlepin API status %d" , statusCode )
5957 }
58+ return & candlepinResp , resp , err
59+ }
6060
61- candlepinRespPtr , err := utils .HTTPCallRetry (candlepinFunc ,
62- candlepin .CandlepinExpRetries , candlepin .CandlepinRetries , http .StatusServiceUnavailable )
61+ func callCandlepinEnvironment (ctx context.Context , consumer string ) (
62+ * candlepin.ConsumersDetailResponse , error ) {
63+ candlepinRespPtr , err := utils .HTTPCallRetry (
64+ func () (interface {}, * http.Response , error ) {
65+ return httpCallCandlepinEnv (ctx , consumer )
66+ },
67+ candlepin .CandlepinExpRetries ,
68+ candlepin .CandlepinRetries ,
69+ http .StatusServiceUnavailable )
6370 if err != nil {
6471 return nil , errors .Wrap (err , "candlepin /consumers call failed" )
6572 }
0 commit comments