Skip to content

Commit

Permalink
Merge pull request #28 from nyaruka/final_tasks_cleanup
Browse files Browse the repository at this point in the history
Final tasks cleanup
  • Loading branch information
rowanseymour authored Feb 7, 2023
2 parents 8b58483 + 826b627 commit a2860de
Show file tree
Hide file tree
Showing 32 changed files with 293 additions and 324 deletions.
21 changes: 10 additions & 11 deletions core/handlers/session_triggered_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/nyaruka/mailroom/runtime"
"github.com/nyaruka/mailroom/testsuite"
"github.com/nyaruka/mailroom/testsuite/testdata"

"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -80,11 +79,11 @@ func TestSessionTriggered(t *testing.T) {
start := models.FlowStart{}
err = json.Unmarshal(task.Task, &start)
assert.NoError(t, err)
assert.True(t, start.CreateContact())
assert.Equal(t, []models.ContactID{testdata.George.ID}, start.ContactIDs())
assert.Equal(t, []models.GroupID{testdata.TestersGroup.ID}, start.GroupIDs())
assert.Equal(t, simpleFlow.ID(), start.FlowID())
assert.JSONEq(t, `{"parent_uuid":"39a9f95e-3641-4d19-95e0-ed866f27c829", "ancestors":1, "ancestors_since_input":1}`, string(start.SessionHistory()))
assert.True(t, start.CreateContact)
assert.Equal(t, []models.ContactID{testdata.George.ID}, start.ContactIDs)
assert.Equal(t, []models.GroupID{testdata.TestersGroup.ID}, start.GroupIDs)
assert.Equal(t, simpleFlow.ID(), start.FlowID)
assert.JSONEq(t, `{"parent_uuid":"39a9f95e-3641-4d19-95e0-ed866f27c829", "ancestors":1, "ancestors_since_input":1}`, string(start.SessionHistory))
return nil
},
},
Expand Down Expand Up @@ -131,11 +130,11 @@ func TestQuerySessionTriggered(t *testing.T) {
start := models.FlowStart{}
err = json.Unmarshal(task.Task, &start)
assert.NoError(t, err)
assert.Equal(t, start.CreateContact(), true)
assert.Equal(t, 0, len(start.ContactIDs()))
assert.Equal(t, 0, len(start.GroupIDs()))
assert.Equal(t, `name ~ "Cathy"`, start.Query())
assert.Equal(t, start.FlowID(), favoriteFlow.ID())
assert.Equal(t, start.CreateContact, true)
assert.Len(t, start.ContactIDs, 0)
assert.Len(t, start.GroupIDs, 0)
assert.Equal(t, `name ~ "Cathy"`, string(start.Query))
assert.Equal(t, start.FlowID, favoriteFlow.ID())
return nil
},
},
Expand Down
5 changes: 2 additions & 3 deletions core/hooks/start_start.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ package hooks
import (
"context"

"github.com/jmoiron/sqlx"
"github.com/nyaruka/mailroom/core/models"
"github.com/nyaruka/mailroom/core/queue"
"github.com/nyaruka/mailroom/core/tasks"
"github.com/nyaruka/mailroom/core/tasks/starts"
"github.com/nyaruka/mailroom/runtime"

"github.com/jmoiron/sqlx"
"github.com/pkg/errors"
)

Expand All @@ -32,7 +31,7 @@ func (h *startStartHook) Apply(ctx context.Context, rt *runtime.Runtime, tx *sql
priority := queue.DefaultPriority

// if we are starting groups, queue to our batch queue instead, but with high priority
if len(start.GroupIDs()) > 0 || start.Query() != "" {
if len(start.GroupIDs) > 0 || start.Query != "" {
taskQ = queue.BatchQueue
priority = queue.HighPriority
}
Expand Down
18 changes: 9 additions & 9 deletions core/ivr/ivr.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func StartIVRFlow(
if err != nil {
return errors.Wrapf(err, "unable to load start: %d", startID)
}
flow, err := oa.FlowByID(start.FlowID())
flow, err := oa.FlowByID(start.FlowID)
if err != nil {
return errors.Wrapf(err, "unable to load flow: %d", startID)
}
Expand All @@ -335,16 +335,16 @@ func StartIVRFlow(
}

var params *types.XObject
if !start.Extra().IsNull() {
params, err = types.ReadXObject(start.Extra())
if !start.Extra.IsNull() {
params, err = types.ReadXObject(start.Extra)
if err != nil {
return errors.Wrap(err, "unable to read JSON from flow start extra")
}
}

var history *flows.SessionHistory
if !start.SessionHistory().IsNull() {
history, err = models.ReadSessionHistory(start.SessionHistory())
if !start.SessionHistory.IsNull() {
history, err = models.ReadSessionHistory(start.SessionHistory)
if err != nil {
return errors.Wrap(err, "unable to read JSON from flow start history")
}
Expand All @@ -354,9 +354,9 @@ func StartIVRFlow(
flowRef := assets.NewFlowReference(flow.UUID(), flow.Name())

var trigger flows.Trigger
if !start.ParentSummary().IsNull() {
if !start.ParentSummary.IsNull() {
trigger = triggers.NewBuilder(oa.Env(), flowRef, contact).
FlowAction(history, json.RawMessage(start.ParentSummary())).
FlowAction(history, json.RawMessage(start.ParentSummary)).
WithCall(channel.ChannelReference(), urn).
Build()
} else {
Expand Down Expand Up @@ -614,9 +614,9 @@ func HandleIVRStatus(ctx context.Context, rt *runtime.Runtime, oa *models.OrgAss
return errors.Wrapf(err, "unable to load start: %d", call.StartID())
}

flow, err := oa.FlowByID(start.FlowID())
flow, err := oa.FlowByID(start.FlowID)
if err != nil {
return errors.Wrapf(err, "unable to load flow: %d", start.FlowID())
return errors.Wrapf(err, "unable to load flow: %d", start.FlowID)
}

call.MarkErrored(ctx, rt.DB, dates.Now(), flow.IVRRetryWait(), errorReason)
Expand Down
11 changes: 5 additions & 6 deletions core/models/schedules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/nyaruka/mailroom/core/models"
"github.com/nyaruka/mailroom/testsuite"
"github.com/nyaruka/mailroom/testsuite/testdata"

"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -81,11 +80,11 @@ func TestGetExpired(t *testing.T) {
assert.Nil(t, schedules[1].Broadcast())
start := schedules[1].FlowStart()
assert.NotNil(t, start)
assert.Equal(t, models.FlowTypeMessaging, start.FlowType())
assert.Equal(t, testdata.Favorites.ID, start.FlowID())
assert.Equal(t, testdata.Org1.ID, start.OrgID())
assert.Equal(t, []models.ContactID{testdata.Cathy.ID, testdata.George.ID}, start.ContactIDs())
assert.Equal(t, []models.GroupID{testdata.DoctorsGroup.ID}, start.GroupIDs())
assert.Equal(t, models.FlowTypeMessaging, start.FlowType)
assert.Equal(t, testdata.Favorites.ID, start.FlowID)
assert.Equal(t, testdata.Org1.ID, start.OrgID)
assert.Equal(t, []models.ContactID{testdata.Cathy.ID, testdata.George.ID}, start.ContactIDs)
assert.Equal(t, []models.GroupID{testdata.DoctorsGroup.ID}, start.GroupIDs)

assert.Equal(t, s1, schedules[2].ID())
bcast := schedules[2].Broadcast()
Expand Down
Loading

0 comments on commit a2860de

Please sign in to comment.