-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #830 from nyaruka/contact_fires
Insert contact fire for session timeout
- Loading branch information
Showing
6 changed files
with
80 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package rapidpro | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"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, extra, fire_on) | ||
VALUES($1, $2, 'T', '', $3, $4) | ||
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.SessionTimeout_) * time.Second) | ||
|
||
_, err := b.db.ExecContext(ctx, sqlInsertTimeoutFire, m.OrgID_, m.ContactID_, jsonx.MustMarshal(extra), timeoutOn) | ||
if err != nil { | ||
return fmt.Errorf("error inserting session timeout contact fire for session #%d: %w", m.SessionID_, err) | ||
} | ||
return nil | ||
} |