Skip to content
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
2 changes: 1 addition & 1 deletion backends/rapidpro/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@
wasSuccess := status.Status() == courier.MsgStatusWired || status.Status() == courier.MsgStatusSent || status.Status() == courier.MsgStatusDelivered || status.Status() == courier.MsgStatusRead
if wasSuccess && dbMsg.Session_ != nil && dbMsg.Session_.Timeout > 0 {
if err := b.insertTimeoutFire(ctx, dbMsg); err != nil {
slog.Error("unable to update session timeout", "error", err, "session_id", dbMsg.SessionID_)
slog.Error("unable to update session timeout", "error", err, "session_uuid", dbMsg.Session_.UUID)

Check warning on line 520 in backends/rapidpro/backend.go

View check run for this annotation

Codecov / codecov/patch

backends/rapidpro/backend.go#L520

Added line #L520 was not covered by tests
}
}

Expand Down
16 changes: 7 additions & 9 deletions backends/rapidpro/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1369,16 +1369,14 @@ func (ts *BackendTestSuite) TestSessionTimeout() {
err := ts.b.insertTimeoutFire(ctx, msg)
ts.NoError(err)

assertdb.Query(ts.T(), ts.b.db, `SELECT org_id, contact_id, fire_type, scope, session_uuid::text, sprint_uuid::text, extra->>'session_id' AS session_id, extra->>'session_modified_on' AS session_modified_on FROM contacts_contactfire`).
assertdb.Query(ts.T(), ts.b.db, `SELECT org_id, contact_id, fire_type, scope, session_uuid::text, sprint_uuid::text FROM contacts_contactfire`).
Columns(map[string]any{
"org_id": int64(1),
"contact_id": int64(100),
"fire_type": "T",
"scope": "",
"session_uuid": "79c1dbc6-4200-4333-b17a-1f996273a4cb",
"sprint_uuid": "0897c392-8b08-43c4-b9d9-e75d332a2c58",
"session_id": "12345",
"session_modified_on": "2025-01-28T20:43:34.157379218Z",
"org_id": int64(1),
"contact_id": int64(100),
"fire_type": "T",
"scope": "",
"session_uuid": "79c1dbc6-4200-4333-b17a-1f996273a4cb",
"sprint_uuid": "0897c392-8b08-43c4-b9d9-e75d332a2c58",
})

// if there's a conflict (e.g. in this case trying to add same timeout again), it should be ignored
Expand Down
4 changes: 0 additions & 4 deletions backends/rapidpro/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ type Msg struct {
channel *Channel
workerToken queue.WorkerToken
alreadyWritten bool

// deprecated
SessionID_ SessionID `json:"session_id"`
SessionModifiedOn_ *time.Time `json:"session_modified_on"`
}

// newMsg creates a new DBMsg object with the passed in parameters
Expand Down
8 changes: 3 additions & 5 deletions backends/rapidpro/timeouts.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,23 @@
"time"

"github.com/nyaruka/gocommon/dates"
"github.com/nyaruka/gocommon/jsonx"
)

// SessionID is our type for RapidPro session ids
type SessionID int64

const sqlInsertTimeoutFire = `
INSERT INTO contacts_contactfire(org_id, contact_id, fire_type, scope, fire_on, session_uuid, sprint_uuid, extra)
VALUES($1, $2, 'T', '', $3, $4, $5, $6)
VALUES($1, $2, 'T', '', $3, $4, $5, '{}')
ON CONFLICT DO NOTHING`

// insertTimeoutFire inserts a timeout fire for the session associated with the given msg
func (b *backend) insertTimeoutFire(ctx context.Context, m *Msg) error {
extra := map[string]any{"session_id": m.SessionID_, "session_modified_on": m.SessionModifiedOn_}
timeoutOn := dates.Now().Add(time.Duration(m.Session_.Timeout) * time.Second)

_, err := b.db.ExecContext(ctx, sqlInsertTimeoutFire, m.OrgID_, m.ContactID_, timeoutOn, m.Session_.UUID, m.Session_.SprintUUID, jsonx.MustMarshal(extra))
_, err := b.db.ExecContext(ctx, sqlInsertTimeoutFire, m.OrgID_, m.ContactID_, timeoutOn, m.Session_.UUID, m.Session_.SprintUUID)
if err != nil {
return fmt.Errorf("error inserting session timeout contact fire for session #%d: %w", m.SessionID_, err)
return fmt.Errorf("error inserting session timeout contact fire for session %s: %w", m.Session_.UUID, err)

Check warning on line 25 in backends/rapidpro/timeouts.go

View check run for this annotation

Codecov / codecov/patch

backends/rapidpro/timeouts.go#L25

Added line #L25 was not covered by tests
}
return nil
}