Skip to content

Commit

Permalink
Don't enqueue discarded events (#253)
Browse files Browse the repository at this point in the history
* Don't enqueue discarded events

* Fixed golden files
  • Loading branch information
subomi authored Dec 2, 2021
1 parent cdc41c7 commit b159e82
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 13 deletions.
6 changes: 3 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ type SMTPConfiguration struct {
}

type GroupConfig struct {
Strategy StrategyConfiguration
Signature SignatureConfiguration
DisableEndpoint bool
Strategy StrategyConfiguration `json:"strategy"`
Signature SignatureConfiguration `json:"signature"`
DisableEndpoint bool `json:"disable_endpoint"`
}

type Configuration struct {
Expand Down
4 changes: 2 additions & 2 deletions docs/docs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Package docs GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
// This file was generated by swaggo/swag at
// 2021-11-25 09:39:39.400508 +0100 WAT m=+37.117529834
// 2021-12-02 21:17:43.731849 +0100 WAT m=+41.298939751
package docs

import (
Expand Down Expand Up @@ -2715,7 +2715,7 @@ var doc = `{
"config.GroupConfig": {
"type": "object",
"properties": {
"disableEndpoint": {
"disable_endpoint": {
"type": "boolean"
},
"signature": {
Expand Down
2 changes: 1 addition & 1 deletion docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2704,7 +2704,7 @@
"config.GroupConfig": {
"type": "object",
"properties": {
"disableEndpoint": {
"disable_endpoint": {
"type": "boolean"
},
"signature": {
Expand Down
2 changes: 1 addition & 1 deletion docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ basePath: /api/v1
definitions:
config.GroupConfig:
properties:
disableEndpoint:
disable_endpoint:
type: boolean
signature:
$ref: '#/definitions/config.SignatureConfiguration'
Expand Down
2 changes: 1 addition & 1 deletion docs/v3/openapi3.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"schemas": {
"config.GroupConfig": {
"properties": {
"disableEndpoint": {
"disable_endpoint": {
"type": "boolean"
},
"signature": {
Expand Down
2 changes: 1 addition & 1 deletion docs/v3/openapi3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ components:
schemas:
config.GroupConfig:
properties:
disableEndpoint:
disable_endpoint:
type: boolean
signature:
$ref: '#/components/schemas/config.SignatureConfiguration'
Expand Down
9 changes: 6 additions & 3 deletions server/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,13 @@ func (a *applicationHandler) CreateAppEvent(w http.ResponseWriter, r *http.Reque

taskName := convoy.EventProcessor.SetPrefix(g.Name)

err = a.eventQueue.Write(r.Context(), taskName, eventDelivery, 1*time.Second)
if err != nil {
log.Errorf("Error occurred sending new event to the queue %s", err)
if eventDelivery.Status != convoy.DiscardedEventStatus {
err = a.eventQueue.Write(r.Context(), taskName, eventDelivery, 1*time.Second)
if err != nil {
log.Errorf("Error occurred sending new event to the queue %s", err)
}
}

}

_ = render.Render(w, r, newServerResponse("App event created successfully", event, http.StatusCreated))
Expand Down
43 changes: 43 additions & 0 deletions server/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,49 @@ func TestApplicationHandler_CreateAppEvent(t *testing.T) {

o, _ := app.groupRepo.(*mocks.MockGroupRepository)

o.EXPECT().
LoadGroups(gomock.Any(), gomock.Any()).Times(1).
Return([]*convoy.Group{group}, nil)
},
},
{
name: "valid message - matching inactive endpoints",
cfgPath: "./testdata/Auth_Config/no-auth-convoy.json",
method: http.MethodPost,
statusCode: http.StatusCreated,
body: strings.NewReader(`{"app_id": "12345", "event_type": "test.event", "data": { "Hello": "World", "Test": "Data" }}`),
args: args{
message: message,
},
dbFn: func(app *applicationHandler) {
a, _ := app.appRepo.(*mocks.MockApplicationRepository)
a.EXPECT().
FindApplicationByID(gomock.Any(), gomock.Any()).Times(1).
Return(&convoy.Application{
UID: appId,
GroupID: groupId,
Title: "Valid application",
Endpoints: []convoy.Endpoint{
{
TargetURL: "http://localhost",
Status: convoy.InactiveEndpointStatus,
Events: []string{"test.event"},
},
},
}, nil)

m, _ := app.eventRepo.(*mocks.MockEventRepository)
m.EXPECT().
CreateEvent(gomock.Any(), gomock.Any()).Times(1).
Return(nil)

ed, _ := app.eventDeliveryRepo.(*mocks.MockEventDeliveryRepository)
ed.EXPECT().
CreateEventDelivery(gomock.Any(), gomock.Any()).
Return(nil)

o, _ := app.groupRepo.(*mocks.MockGroupRepository)

o.EXPECT().
LoadGroups(gomock.Any(), gomock.Any()).Times(1).
Return([]*convoy.Group{group}, nil)
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"status":true,"message":"Group updated successfully","data":{"uid":"1234567890","name":"ABC_DEF_TEST_UPDATE","logo_url":"","config":{"Strategy":{"type":"","default":{"intervalSeconds":0,"retryLimit":0}},"Signature":{"header":"","hash":""},"DisableEndpoint":false}}}
{"status":true,"message":"Group updated successfully","data":{"uid":"1234567890","name":"ABC_DEF_TEST_UPDATE","logo_url":"","config":{"strategy":{"type":"","default":{"intervalSeconds":0,"retryLimit":0}},"signature":{"header":"","hash":""},"disable_endpoint":false}}}

0 comments on commit b159e82

Please sign in to comment.