Skip to content

Commit

Permalink
Cleanup use of Flow.metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Apr 13, 2020
1 parent b1c7ad3 commit 0e4dc9b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 28 deletions.
4 changes: 2 additions & 2 deletions ivr/ivr.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,8 +608,8 @@ func HandleIVRStatus(ctx context.Context, db *sqlx.DB, rp *redis.Pool, org *mode
return errors.Wrapf(err, "unable to load flow: %d", start.FlowID())
}

retryWait := time.Minute * time.Duration(flow.IntConfigValue(models.FlowConfigIVRRetryMinutes, models.ConnectionRetryWait))
conn.MarkErrored(ctx, db, time.Now(), retryWait)
conn.MarkErrored(ctx, db, time.Now(), flow.IVRRetryWait())

if conn.Status() == models.ConnectionStatusErrored {
return client.WriteEmptyResponse(w, fmt.Sprintf("status updated: %s next_attempt: %s", conn.Status(), conn.NextAttempt()))
}
Expand Down
Binary file modified mailroom_test.dump
Binary file not shown.
4 changes: 2 additions & 2 deletions models/channel_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ const (

ConnectionMaxRetries = 3

// ConnectionRetryWait is our default wait to retry connections in minutes
ConnectionRetryWait = 60
// ConnectionRetryWait is our default wait to retry connections
ConnectionRetryWait = time.Minute * 60

// ConnectionThrottleWait is our wait between throttle retries
ConnectionThrottleWait = time.Minute * 2
Expand Down
17 changes: 5 additions & 12 deletions models/flows.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,14 @@ func (f *Flow) FlowType() FlowType { return f.f.FlowType }
// Version returns the version this flow was authored in
func (f *Flow) Version() string { return f.f.Version }

// IntConfigValue returns the value for the key passed in as an int. If the value
// is not an integer or is not present then the defaultValue is returned
func (f *Flow) IntConfigValue(key string, defaultValue int64) int64 {
value := f.f.Config.Get(key, defaultValue)
// IVRRetryWait returns the wait before retrying a failed IVR call
func (f *Flow) IVRRetryWait() time.Duration {
value := f.f.Config.Get(FlowConfigIVRRetryMinutes, nil)
fv, isFloat := value.(float64)
if isFloat {
return int64(fv)
return time.Minute * time.Duration(int(fv))
}
return defaultValue
}

// StringConfigValue returns the value for the key passed in as a string. If the value
// is not a string or is not present then the defaultValue is returned
func (f *Flow) StringConfigValue(key string, defaultValue string) string {
return f.f.Config.GetString(key, defaultValue)
return ConnectionRetryWait
}

// IgnoreTriggers returns whether this flow ignores triggers
Expand Down
24 changes: 12 additions & 12 deletions models/flows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package models

import (
"testing"
"time"

"github.com/nyaruka/goflow/assets"
"github.com/nyaruka/mailroom/goflow"
Expand All @@ -13,15 +14,18 @@ func TestFlows(t *testing.T) {
ctx := testsuite.CTX()
db := testsuite.DB()

db.MustExec(`UPDATE flows_flow SET metadata = '{"ivr_retry": 30}'::json WHERE id = $1`, IVRFlowID)

tcs := []struct {
OrgID OrgID
FlowID FlowID
FlowUUID assets.FlowUUID
Name string
ExpiresAfterMinutes int64
Found bool
OrgID OrgID
FlowID FlowID
FlowUUID assets.FlowUUID
Name string
IVRRetry time.Duration
Found bool
}{
{Org1, FavoritesFlowID, FavoritesFlowUUID, "Favorites", 720, true},
{Org1, FavoritesFlowID, FavoritesFlowUUID, "Favorites", 60 * time.Minute, true},
{Org1, IVRFlowID, IVRFlowUUID, "IVR Flow", 30 * time.Minute, true},
{Org2, FlowID(0), assets.FlowUUID("51e3c67d-8483-449c-abf7-25e50686f0db"), "", 0, false},
}

Expand All @@ -33,11 +37,7 @@ func TestFlows(t *testing.T) {
assert.Equal(t, tc.Name, flow.Name())
assert.Equal(t, tc.FlowID, flow.ID())
assert.Equal(t, tc.FlowUUID, flow.UUID())

assert.Equal(t, tc.ExpiresAfterMinutes, flow.IntConfigValue("expires", 0))
assert.Equal(t, int64(10), flow.IntConfigValue("not_there", 10))
assert.Equal(t, tc.Name, flow.StringConfigValue("name", "missing"))
assert.Equal(t, "missing", flow.StringConfigValue("not_there", "missing"))
assert.Equal(t, tc.IVRRetry, flow.IVRRetryWait())

_, err := goflow.ReadFlow(flow.Definition())
assert.NoError(t, err)
Expand Down

0 comments on commit 0e4dc9b

Please sign in to comment.