Skip to content

Commit

Permalink
Merge pull request #71 from Ilhasoft/update/v6.5.2
Browse files Browse the repository at this point in the history
Update/v6.5.2
  • Loading branch information
jcbalmeida authored Aug 3, 2021
2 parents b133e73 + cee38d1 commit 7a9e508
Show file tree
Hide file tree
Showing 23 changed files with 274 additions and 126 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: CI
on: [push, pull_request]
env:
go-version: '1.15.x'
go-version: '1.16.x'
jobs:
test:
name: Test
Expand Down
39 changes: 39 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,42 @@
v6.5.2
----------
* Add ticket_count column to contact and set to zero when creating new contacts

v6.5.1
----------
* Give S3 storage test new context on startup
* Make DBMsg.SentOn nullable

v6.5.0
----------
* Always set sent_on for W/S/D statuses if not already set
* Update to latest gocommon

v6.4.0
----------
* 6.4.0 Release Candidate

v6.3.5
----------
* up max request size to 1M

v6.3.4
----------
* Include filename when sending WhatsApp attachments

v6.3.3
----------
* Support using namespace from the template translation
* Add is_resend to Msg payload to allow for resending messages manually

v6.3.2
----------
* Do not verify the SSL certificate for Bongo Live

v6.3.1
----------
* Update BL to remove UDH parameter and use HTTPS URL

v6.2.2
----------
* Handle whatsapp URNs sent to Twiml handler without prefix
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Courier
# Courier

[![Build Status](https://github.com/nyaruka/courier/workflows/CI/badge.svg)](https://github.com/nyaruka/courier/actions?query=workflow%3ACI)
[![codecov](https://codecov.io/gh/nyaruka/courier/branch/main/graph/badge.svg)](https://codecov.io/gh/nyaruka/courier)
Expand Down
6 changes: 5 additions & 1 deletion backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ type Backend interface {

// WasMsgSent returns whether the backend thinks the passed in message was already sent. This can be used in cases where
// a backend wants to implement a failsafe against double sending messages (say if they were double queued)
WasMsgSent(context.Context, Msg) (bool, error)
WasMsgSent(context.Context, MsgID) (bool, error)

// ClearMsgSent clears any internal status that a message was previously sent. This can be used in the case where
// a message is being forced in being resent by a user
ClearMsgSent(context.Context, MsgID) error

// IsMsgLoop returns whether the passed in message is part of a message loop, possibly with another bot. Backends should
// implement their own logic to implement this.
Expand Down
37 changes: 23 additions & 14 deletions backends/rapidpro/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,29 @@ var luaSent = redis.NewScript(3,
`)

// WasMsgSent returns whether the passed in message has already been sent
func (b *backend) WasMsgSent(ctx context.Context, msg courier.Msg) (bool, error) {
func (b *backend) WasMsgSent(ctx context.Context, id courier.MsgID) (bool, error) {
rc := b.redisPool.Get()
defer rc.Close()

todayKey := fmt.Sprintf(sentSetName, time.Now().UTC().Format("2006_01_02"))
yesterdayKey := fmt.Sprintf(sentSetName, time.Now().Add(time.Hour*-24).UTC().Format("2006_01_02"))
return redis.Bool(luaSent.Do(rc, todayKey, yesterdayKey, msg.ID().String()))
return redis.Bool(luaSent.Do(rc, todayKey, yesterdayKey, id.String()))
}

var luaClearSent = redis.NewScript(3,
`-- KEYS: [TodayKey, YesterdayKey, MsgID]
redis.call("srem", KEYS[1], KEYS[3])
redis.call("srem", KEYS[2], KEYS[3])
`)

func (b *backend) ClearMsgSent(ctx context.Context, id courier.MsgID) error {
rc := b.redisPool.Get()
defer rc.Close()

todayKey := fmt.Sprintf(sentSetName, time.Now().UTC().Format("2006_01_02"))
yesterdayKey := fmt.Sprintf(sentSetName, time.Now().Add(time.Hour*-24).UTC().Format("2006_01_02"))
_, err := luaClearSent.Do(rc, todayKey, yesterdayKey, id.String())
return err
}

var luaMsgLoop = redis.NewScript(3, `-- KEYS: [key, contact_id, text]
Expand Down Expand Up @@ -330,16 +346,7 @@ func (b *backend) WriteMsgStatus(ctx context.Context, status courier.MsgStatus)

// if we have an id and are marking an outgoing msg as errored, then clear our sent flag
if status.ID() != courier.NilMsgID && status.Status() == courier.MsgErrored {
rc := b.redisPool.Get()
defer rc.Close()

dateKey := fmt.Sprintf(sentSetName, time.Now().UTC().Format("2006_01_02"))
prevDateKey := fmt.Sprintf(sentSetName, time.Now().Add(time.Hour*-24).UTC().Format("2006_01_02"))

// we pipeline the removals because we don't care about the return value
rc.Send("srem", dateKey, status.ID().String())
rc.Send("srem", prevDateKey, status.ID().String())
_, err := rc.Do("")
err := b.ClearMsgSent(ctx, status.ID())
if err != nil {
logrus.WithError(err).WithField("msg", status.ID().String()).Error("error clearing sent flags")
}
Expand Down Expand Up @@ -687,13 +694,15 @@ func (b *backend) Start() error {
if err != nil {
return err
}
b.storage = storage.NewS3(s3Client, b.config.S3MediaBucket)
b.storage = storage.NewS3(s3Client, b.config.S3MediaBucket, b.config.S3Region, 32)
} else {
b.storage = storage.NewFS("_storage")
}

// test our storage
err = b.storage.Test()
ctx, cancel = context.WithTimeout(context.Background(), 3*time.Second)
err = b.storage.Test(ctx)
cancel()
if err != nil {
log.WithError(err).Error(b.storage.Name() + " storage not available")
} else {
Expand Down
Loading

0 comments on commit 7a9e508

Please sign in to comment.