@@ -2,8 +2,8 @@ package scalingo
22
33import (
44 "context"
5+ "encoding/json"
56 "fmt"
6- "net/http"
77 "time"
88
99 httpclient "github.com/Scalingo/go-scalingo/v10/http"
@@ -32,7 +32,7 @@ type AppsService interface {
3232 AppsStats (ctx context.Context , app string ) (* AppStatsRes , error )
3333 AppsContainerTypes (ctx context.Context , app string ) ([]ContainerType , error )
3434 AppsContainersPs (ctx context.Context , app string ) ([]Container , error )
35- AppsScale (ctx context.Context , app string , params * AppsScaleParams ) (* http. Response , error )
35+ AppsScale (ctx context.Context , app string , params * AppsScaleParams ) ([] ContainerType , string , error )
3636 AppsForceHTTPS (ctx context.Context , name string , enable bool ) (* App , error )
3737 AppsStickySession (ctx context.Context , name string , enable bool ) (* App , error )
3838 AppsRouterLogs (ctx context.Context , name string , enable bool ) (* App , error )
@@ -313,7 +313,12 @@ func (c *Client) AppsContainerTypes(ctx context.Context, app string) ([]Containe
313313 return containerTypesRes .Containers , nil
314314}
315315
316- func (c * Client ) AppsScale (ctx context.Context , app string , params * AppsScaleParams ) (* http.Response , error ) {
316+ type ScaleRes struct {
317+ Containers []ContainerType `json:"containers"`
318+ }
319+
320+ // AppsScale scales an app and returns the updated containers and the operation URL when scaling is processed asynchronously.
321+ func (c * Client ) AppsScale (ctx context.Context , app string , params * AppsScaleParams ) ([]ContainerType , string , error ) {
317322 req := & httpclient.APIRequest {
318323 Method : "POST" ,
319324 Endpoint : "/apps/" + app + "/scale" ,
@@ -322,9 +327,18 @@ func (c *Client) AppsScale(ctx context.Context, app string, params *AppsScalePar
322327 // Otherwise async job is triggered, it's 202
323328 Expected : httpclient.Statuses {200 , 202 },
324329 }
325- var res * http.Response
326- err := c .ScalingoAPI ().DoRequest (ctx , req , & res )
327- return res , err
330+ res , err := c .ScalingoAPI ().Do (ctx , req )
331+ if err != nil {
332+ return nil , "" , errors .Wrap (ctx , err , "request Scalingo API to scale the application" )
333+ }
334+
335+ var scaleRes ScaleRes
336+ err = json .NewDecoder (res .Body ).Decode (& scaleRes )
337+ if err != nil {
338+ return nil , "" , errors .Wrapf (ctx , err , "decode API response to scale request" )
339+ }
340+
341+ return scaleRes .Containers , res .Header .Get ("Location" ), nil
328342}
329343
330344func (c * Client ) AppsForceHTTPS (ctx context.Context , name string , enable bool ) (* App , error ) {
0 commit comments