Skip to content

Commit

Permalink
Reorder webhook call when updating routers
Browse files Browse the repository at this point in the history
  • Loading branch information
deadlycoconuts committed Nov 5, 2024
1 parent f83562a commit 18f0c0f
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 37 deletions.
2 changes: 1 addition & 1 deletion api/turing/api/deployment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (c RouterDeploymentController) writeDeploymentEvents(
// (current version reference, status, endpoint, etc.) are not in the scope of this method.
// This method returns the new router endpoint (if successful) and any error.
func (c RouterDeploymentController) deployRouterVersion(
ctx context.Context,
_ context.Context,
project *mlp.Project,
environment *merlin.Environment,
routerVersion *models.RouterVersion,
Expand Down
5 changes: 2 additions & 3 deletions api/turing/api/router_versions_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ package api

import (
"fmt"
"github.com/caraml-dev/turing/api/turing/webhook"
"net/http"

"github.com/caraml-dev/turing/api/turing/service"

mlp "github.com/caraml-dev/mlp/api/client"

"github.com/caraml-dev/turing/api/turing/api/request"
"github.com/caraml-dev/turing/api/turing/log"
"github.com/caraml-dev/turing/api/turing/models"
"github.com/caraml-dev/turing/api/turing/service"
"github.com/caraml-dev/turing/api/turing/webhook"
)

type RouterVersionsController struct {
Expand Down
9 changes: 5 additions & 4 deletions api/turing/api/router_versions_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@ package api

import (
"errors"
"github.com/caraml-dev/turing/api/turing/webhook"
webhookMock "github.com/caraml-dev/turing/api/turing/webhook/mocks"
"net/http"
"testing"

merlin "github.com/caraml-dev/merlin/client"
mlp "github.com/caraml-dev/mlp/api/client"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"

merlin "github.com/caraml-dev/merlin/client"
mlp "github.com/caraml-dev/mlp/api/client"

"github.com/caraml-dev/turing/api/turing/api/request"
"github.com/caraml-dev/turing/api/turing/config"
"github.com/caraml-dev/turing/api/turing/models"
"github.com/caraml-dev/turing/api/turing/service/mocks"
"github.com/caraml-dev/turing/api/turing/webhook"
webhookMock "github.com/caraml-dev/turing/api/turing/webhook/mocks"
routerConfig "github.com/caraml-dev/turing/engines/router/missionctl/config"
)

Expand Down
12 changes: 6 additions & 6 deletions api/turing/api/routers_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,13 @@ func (c RoutersController) UpdateRouter(req *http.Request, vars RequestVars, bod
log.Errorf("Error deploying router %s:%s:%d: %v",
project.Name, router.Name, routerVersion.Version, err)
}
}()

// call webhook for router update event
if errWebhook := c.webhookClient.TriggerWebhooks(ctx, webhook.OnRouterUpdated, router); errWebhook != nil {
log.Warnf("Error triggering webhook for event %s, router id: %d, %v",
webhook.OnRouterUpdated, router.ID, errWebhook)
}
// call webhook for router update event
if errWebhook := c.webhookClient.TriggerWebhooks(ctx, webhook.OnRouterUpdated, router); errWebhook != nil {
log.Warnf("Error triggering webhook for event %s, router id: %d, %v",
webhook.OnRouterUpdated, router.ID, errWebhook)
}
}()

return Ok(router)
}
Expand Down
46 changes: 23 additions & 23 deletions api/turing/api/routers_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import (
"net/http"
"testing"

"github.com/caraml-dev/turing/api/turing/webhook"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"

merlin "github.com/caraml-dev/merlin/client"
mlp "github.com/caraml-dev/mlp/api/client"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"

"github.com/caraml-dev/turing/api/turing/api/request"
"github.com/caraml-dev/turing/api/turing/config"
"github.com/caraml-dev/turing/api/turing/models"
"github.com/caraml-dev/turing/api/turing/service/mocks"
"github.com/caraml-dev/turing/api/turing/webhook"
webhookMock "github.com/caraml-dev/turing/api/turing/webhook/mocks"
routerConfig "github.com/caraml-dev/turing/engines/router/missionctl/config"
)
Expand Down Expand Up @@ -468,26 +468,26 @@ func TestUpdateRouter(t *testing.T) {
vars: RequestVars{"project_id": {"2"}, "router_id": {"3"}},
expected: InternalServerError("unable to update router", "router config is empty"),
},
//"success": {
// req: &http.Request{},
// body: &request.CreateOrUpdateRouterRequest{
// Name: "router4",
// Environment: "dev",
// Config: &request.RouterConfig{
// ExperimentEngine: &request.ExperimentEngineConfig{
// Type: "nop",
// },
// LogConfig: &request.LogConfig{
// ResultLoggerType: models.NopLogger,
// },
// },
// },
// vars: RequestVars{"project_id": {"2"}, "router_id": {"4"}},
// expected: &Response{
// code: 200,
// data: router4,
// },
//},
"success": {
req: &http.Request{},
body: &request.CreateOrUpdateRouterRequest{
Name: "router4",
Environment: "dev",
Config: &request.RouterConfig{
ExperimentEngine: &request.ExperimentEngineConfig{
Type: "nop",
},
LogConfig: &request.LogConfig{
ResultLoggerType: models.NopLogger,
},
},
},
vars: RequestVars{"project_id": {"2"}, "router_id": {"4"}},
expected: &Response{
code: 200,
data: router4,
},
},
}

// Run tests
Expand Down

0 comments on commit 18f0c0f

Please sign in to comment.