Skip to content

Commit

Permalink
Add CI for event logger
Browse files Browse the repository at this point in the history
  • Loading branch information
dwilkie committed Mar 28, 2024
1 parent 81a85bd commit 0940997
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 22 deletions.
14 changes: 13 additions & 1 deletion .github/workflows/switch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,20 @@ jobs:
bundle exec rspec
- name: Run FreeSWITCH tests
working-directory: components/freeswitch
run: |
../freeswitch/tests/tests.sh
./tests/tests.sh
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: "1.21.x"

- name: Run tests
working-directory: components/freeswitch_event_logger
run: |
go get .
go test
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
Expand Down
27 changes: 14 additions & 13 deletions components/freeswitch_event_logger/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func logHeartbeat(eventStr string, connIdx int) {
fmt.Println(string(jsonString))
}

func processIncomingEvent(eventStr string) (string, string, error) {
func parseEvent(eventStr string) (string, string, error) {
eventMap := fsock.FSEventStrToMap(eventStr, []string{})

eventName := eventMap["Event-Subclass"]
Expand All @@ -57,19 +57,19 @@ func processIncomingEvent(eventStr string) (string, string, error) {
return "", "", fmt.Errorf("Event does not contain streamSid: " + eventMap["Event-Payload"])
}

fmt.Println("Publishing Event:" + eventMap["Event-Payload"])
redisChannel := modTwilioStreamPrefix + ":" + streamSid
return redisChannel, eventMap["Event-Payload"], nil
}

func customEventHandler(ctx context.Context, rdb *redis.Client, eventStr string) {
redisChannel, redisMsg, e := processIncomingEvent(eventStr)
func customEventHandler(ctx context.Context, redisClient *redis.Client, eventStr string) {
redisChannel, redisMsg, parseEventError := parseEvent(eventStr)

if e != nil {
fmt.Println(" Error: " + e.Error())
if parseEventError != nil {
fmt.Println("Error: " + parseEventError.Error())
return
}
redisError := rdb.Publish(ctx, redisChannel, redisMsg).Err()

redisError := redisClient.Publish(ctx, redisChannel, redisMsg).Err()
if redisError != nil {
fmt.Println("Problem publishing to Redis channel: " + redisChannel + " Payload: " + redisMsg + " Error: " + redisError.Error())
}
Expand All @@ -90,16 +90,17 @@ func fibDuration(durationUnit, maxDuration time.Duration) func() time.Duration {
func main() {
ctx := context.Background()

redis_url := os.Getenv("REDIS_URL")
opt, e := redis.ParseURL(redis_url)
if e != nil {
panic(e)
redisUrl := os.Getenv("REDIS_URL")
redisOptions, redisError := redis.ParseURL(redisUrl)

if redisError != nil {
panic(redisError)
}

rdb := redis.NewClient(opt)
redisClient := redis.NewClient(redisOptions)

customEventHandlerWrapper := func(eventStr string, connIdx int) {
customEventHandler(ctx, rdb, eventStr)
customEventHandler(ctx, redisClient, eventStr)
}

evFilters := map[string][]string{
Expand Down
8 changes: 4 additions & 4 deletions components/freeswitch_event_logger/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
)

func TestParseEventFail(t *testing.T) {
_, _, e := processIncomingEvent("")
if e == nil {
_, _, parseEventError := parseEvent("")
if parseEventError == nil {
t.Errorf("got pass expected error")
}
}
Expand All @@ -21,9 +21,9 @@ Event-Payload: %7B%22event%22%3A%20%22disconnect%22,%22accountSid%22%3A%20%22c46
wantRedisChannel := `mod_twilio_stream:5cc24afd-ea42-4605-858d-5c47b597b646`
wantRedisMsg := `{"event": "disconnect","accountSid": "c4612957-a00a-480d-a168-c75fbf29b2db","callSid": "21fb5eee-ce7c-4e30-a069-439fa0269aeb","streamSid": "5cc24afd-ea42-4605-858d-5c47b597b646"}`

redisChannel, redisMsg, e := processIncomingEvent(incomingMsg)
redisChannel, redisMsg, parseEventError := parseEvent(incomingMsg)

if e != nil {
if parseEventError != nil {
t.Errorf("Unexpected error")
}

Expand Down
6 changes: 4 additions & 2 deletions components/freeswitch_event_logger/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ module freeswitch_event_logger

go 1.22.1

require github.com/cgrates/fsock v0.0.0-20240321180839-4d5a76e3d51b
require (
github.com/cgrates/fsock v0.0.0-20240322171959-35309017b3e0
github.com/redis/go-redis/v9 v9.5.1
)

require (
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/redis/go-redis/v9 v9.5.1 // indirect
)
8 changes: 6 additions & 2 deletions components/freeswitch_event_logger/go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cgrates/fsock v0.0.0-20240321180839-4d5a76e3d51b h1:Bic97hsz2iD/WloybKBJmiu5+cFYw6c1vh80872v1tU=
github.com/cgrates/fsock v0.0.0-20240321180839-4d5a76e3d51b/go.mod h1:bKByLko2HF33K+PbiiToAgevrrbr96C+7Pp3HGS6oag=
github.com/cgrates/fsock v0.0.0-20240322171959-35309017b3e0 h1:rnSM0tG6Cl8GXjyBQXw78WEaJolKfZqHTXkOCZh+w/k=
github.com/cgrates/fsock v0.0.0-20240322171959-35309017b3e0/go.mod h1:bKByLko2HF33K+PbiiToAgevrrbr96C+7Pp3HGS6oag=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/redis/go-redis/v9 v9.5.1 h1:H1X4D3yHPaYrkL5X06Wh6xNVM/pX0Ft4RV0vMGvLBh8=
Expand Down

0 comments on commit 0940997

Please sign in to comment.