Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Msg.failed_reason #391

Merged
merged 1 commit into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions backends/rapidpro/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ func (ts *BackendTestSuite) TestMsgStatus() {
ts.Equal(null.String("ext0"), m.ExternalID_)
ts.True(m.ModifiedOn_.After(now))
ts.True(m.SentOn_.After(now))
ts.Equal(null.NullString, m.FailedReason_)

sentOn := *m.SentOn_

Expand Down Expand Up @@ -584,6 +585,7 @@ func (ts *BackendTestSuite) TestMsgStatus() {
ts.Equal(m.ErrorCount_, 1)
ts.True(m.ModifiedOn_.After(now))
ts.True(m.NextAttempt_.After(now))
ts.Equal(null.NullString, m.FailedReason_)

// second go
status = ts.b.NewMsgStatusForExternalID(channel, "ext1", courier.MsgErrored)
Expand All @@ -594,6 +596,7 @@ func (ts *BackendTestSuite) TestMsgStatus() {
m = readMsgFromDB(ts.b, courier.NewMsgID(10000))
ts.Equal(m.Status_, courier.MsgErrored)
ts.Equal(m.ErrorCount_, 2)
ts.Equal(null.NullString, m.FailedReason_)

// third go
status = ts.b.NewMsgStatusForExternalID(channel, "ext1", courier.MsgErrored)
Expand All @@ -604,6 +607,7 @@ func (ts *BackendTestSuite) TestMsgStatus() {
m = readMsgFromDB(ts.b, courier.NewMsgID(10000))
ts.Equal(m.Status_, courier.MsgFailed)
ts.Equal(m.ErrorCount_, 3)
ts.Equal(null.String("E"), m.FailedReason_)

// update URN when the new doesn't exist
tx, _ := ts.b.db.BeginTxx(ctx, nil)
Expand Down
6 changes: 4 additions & 2 deletions backends/rapidpro/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ SELECT
attachments,
msg_count,
error_count,
failed_reason,
high_priority,
status,
visibility,
Expand Down Expand Up @@ -497,8 +498,9 @@ type DBMsg struct {
ContactID_ ContactID `json:"contact_id" db:"contact_id"`
ContactURNID_ ContactURNID `json:"contact_urn_id" db:"contact_urn_id"`

MessageCount_ int `json:"msg_count" db:"msg_count"`
ErrorCount_ int `json:"error_count" db:"error_count"`
MessageCount_ int `json:"msg_count" db:"msg_count"`
ErrorCount_ int `json:"error_count" db:"error_count"`
FailedReason_ null.String `json:"failed_reason" db:"failed_reason"`

ChannelUUID_ courier.ChannelUUID `json:"channel_uuid"`
ContactName_ string `json:"contact_name"`
Expand Down
4 changes: 3 additions & 1 deletion backends/rapidpro/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,16 @@ CREATE TABLE msgs_msg (
msg_count integer NOT NULL,
error_count integer NOT NULL,
next_attempt timestamp with time zone NOT NULL,
failed_reason character varying(1),
external_id character varying(255),
attachments character varying(255)[],
channel_id integer references channels_channel(id) on delete cascade,
contact_id integer NOT NULL references contacts_contact(id) on delete cascade,
contact_urn_id integer NOT NULL references contacts_contacturn(id) on delete cascade,
org_id integer NOT NULL references orgs_org(id) on delete cascade,
metadata text,
topup_id integer
topup_id integer,
delete_from_counts boolean
);

DROP TABLE IF EXISTS channels_channellog CASCADE;
Expand Down
16 changes: 16 additions & 0 deletions backends/rapidpro/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ UPDATE msgs_msg SET
ELSE
next_attempt
END,
failed_reason = CASE
WHEN
error_count >= 2
THEN
'E'
ELSE
failed_reason
END,
sent_on = CASE
WHEN
:status = 'W'
Expand Down Expand Up @@ -164,6 +172,14 @@ UPDATE msgs_msg SET
ELSE
next_attempt
END,
failed_reason = CASE
WHEN
error_count >= 2
THEN
'E'
ELSE
failed_reason
END,
sent_on = CASE
WHEN
:status IN ('W', 'S', 'D')
Expand Down