Skip to content

Commit

Permalink
Merge tag 'v7.4.1' into update/v7.4.1-mailroom
Browse files Browse the repository at this point in the history
 * Update to latest goflow
  • Loading branch information
Robi9 committed Nov 30, 2022
2 parents 78f5a44 + 4ba0425 commit 79f0600
Show file tree
Hide file tree
Showing 121 changed files with 3,104 additions and 2,064 deletions.
6 changes: 3 additions & 3 deletions .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.17.x"
go-version: "1.18.x"
postgis-version: "3.1"
redis-version: "5.0.6"
jobs:
Expand Down Expand Up @@ -50,9 +50,9 @@ jobs:
- name: Upload coverage
if: success()
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v2
with:
fail_ci_if_error: false
fail_ci_if_error: true

release:
name: Release
Expand Down
111 changes: 111 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,114 @@
v7.4.1
----------
* Update to latest goflow

v7.4.0
----------
* Update README

v7.3.20
----------
* Use proper query construction for preview_start endpoint and return search errors for invalid user queries

v7.3.19
----------
* Update dependencies
* Log version at startup

v7.3.18
----------
* Use new orgmembership table to load users
* Update to latest goflow

v7.3.17
----------
* Update to latest goflow and simplify code for exiting session runs
* Add support for excluding contacts already in a flow in start_session actions
* Don't blow up in msg_created handler if flow has been deleted
* Use analytics package from gocommon instead of librato directly

v7.3.16
----------
* Update to latest goflow

v7.3.15
----------
* Simplify BroadcastBatch
* Record first-reply timings for tickets
* Add arm64 as a build target

v7.3.14
----------
* Update to latest goflow which fixes contact query bug

v7.3.13
----------
* Update to latest goflow which fixes contact query simplification
* Record ticket daily counts when opening, assigning and replying to tickets
* Update to latest gocommon, phonenumbers, jsonparser

v7.3.12
----------
* Update to go 1.18 and use some generics

v7.3.11
----------
* Rework flow/preview_start endpoint to take a number of days since last seen on
* Update to latest goflow that has fix for whatsapp template selection

v7.3.10
----------
* Changes to preview_start endpoint - 1) rename count to total to match other search endpoints, 2) add
query inspection metadata to preview_start endpoint response 3) switch to UUIDs for contacts and groups

v7.3.9
----------
* Move search into its own package and add more tests
* Add endpoint to generate a flow start preview

v7.3.8
----------
* Use new contactfield.name and is_system fields

v7.3.7
----------
* Update to latest goflow and start using httpx.DetectContentType

v7.3.6
----------
* Update modified_on for flow history changes by handling flow entered and sprint ended
events

v7.3.5
----------
* Update to latest goflow which requires mapping groups and flows to ids for ES queries

v7.3.4
----------
* Fix unstopping of contacts who message in

v7.3.3
----------
* ContactGroup.group_type can no longer be 'U'
* Clear session timeout if timeout resume rejected by wait
* Update golang.org/x/sys

v7.3.2
----------
* Add is_system to contact groups, filter groups by group_type = M|Q|U

v7.3.1
----------
* Simplify cron jobs and add them to the main mailroom waitgroup
* Allow expirations and timeouts to resume sessions for stopped, blocked and archived contacts
* Messages to stopped, blocked or archived contacts should immediately fail

v7.3.0
----------
* Update to latest goflow
* Replace last usages of old locker code
* Cleanup some SQL variables

v7.2.6
----------
* Batch calls to delete event fires
Expand Down
25 changes: 12 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
# mailroom
# Mailroom

[![Build Status](https://github.com/nyaruka/mailroom/workflows/CI/badge.svg)](https://github.com/nyaruka/mailroom/actions?query=workflow%3ACI)
[![codecov](https://codecov.io/gh/nyaruka/mailroom/branch/main/graph/badge.svg)](https://codecov.io/gh/nyaruka/mailroom)

# About
Service for RapidPro/TextIt which does the heavy lifting of running flow starts, campaigns etc.
flows. It interacts directly with the database and sends and receives messages with [Courier](https://github.com/nyaruka/courier)
for handling via Redis.

Mailroom is the [RapidPro](https://github.com/rapidpro/rapidpro) components which does the heavy lifting of running flow starts, campaigns etc.
flows. It interacts directly with the RapidPro database and sends and receives messages with [Courier](https://github.com/nyaruka/courier) for handling via Redis.
## Deploying

# Deploying

As Mailroom is a Go application, it compiles to a binary and that binary along with the config file is all
As a Go application, it compiles to a binary and that binary along with the config file is all
you need to run it on your server. You can find bundles for each platform in the
[releases directory](https://github.com/nyaruka/mailroom/releases). We recommend running Mailroom
[releases directory](https://github.com/nyaruka/mailroom/releases). We recommend running it
behind a reverse proxy such as nginx or Elastic Load Balancer that provides HTTPs encryption.

# Configuration
## Configuration

Mailroom uses a tiered configuration system, each option takes precendence over the ones above it:
The service uses a tiered configuration system, each option takes precendence over the ones above it:

1. The configuration file
2. Environment variables starting with `MAILROOM_`
3. Command line parameters

We recommend running Mailroom with no changes to the configuration and no parameters, using only
We recommend running it with no changes to the configuration and no parameters, using only
environment variables to configure it. You can use `% mailroom --help` to see a list of the
environment variables and parameters and for more details on each option.

Expand Down Expand Up @@ -67,9 +66,9 @@ Recommended settings for error and performance monitoring:
- `MAILROOM_SENTRY_DSN`: The DSN to use when logging errors to Sentry
- `MAILROOM_LOG_LEVEL`: the logging level mailroom should use (default "error", use "debug" for more)

# Development
## Development

Once you've checked out the code, you can build Mailroom with:
Once you've checked out the code, you can build the service with:

```
go build github.com/nyaruka/mailroom/cmd/mailroom
Expand Down
20 changes: 11 additions & 9 deletions cmd/mailroom/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,15 @@ import (
"github.com/sirupsen/logrus"
)

var version = "Dev"
var (
// https://goreleaser.com/cookbooks/using-main.version
version = "dev"
date = "unknown"
)

func main() {
config := runtime.NewDefaultConfig()
config.Version = version
loader := ezconf.NewLoader(
config,
"mailroom", "Mailroom - flow event handler for RapidPro",
Expand All @@ -65,18 +70,15 @@ func main() {
logrus.Fatalf("invalid config: %s", err)
}

// if we have a custom version, use it
if version != "Dev" {
config.Version = version
}

// configure our logger
logrus.SetOutput(os.Stdout)
level, err := logrus.ParseLevel(config.LogLevel)
if err != nil {
logrus.Fatalf("invalid log level '%s'", level)
}

logrus.SetLevel(level)
logrus.SetOutput(os.Stdout)
logrus.SetFormatter(&logrus.TextFormatter{})
logrus.WithField("version", version).WithField("released", date).Info("starting mailroom")

// if we have a DSN entry, try to initialize it
if config.SentryDSN != "" {
Expand Down Expand Up @@ -109,7 +111,7 @@ func main() {

// handleSignals takes care of trapping quit, interrupt or terminate signals and doing the right thing
func handleSignals(mr *mailroom.Mailroom) {
sigs := make(chan os.Signal)
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)

for {
Expand Down
1 change: 1 addition & 0 deletions core/handlers/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ func createTestFlow(t *testing.T, uuid assets.FlowUUID, tc TestCase) flows.Flow
definition.NewLocalization(),
nodes,
nil,
nil,
)
require.NoError(t, err)

Expand Down
28 changes: 0 additions & 28 deletions core/handlers/contact_flow_changed.go

This file was deleted.

7 changes: 2 additions & 5 deletions core/handlers/contact_status_changed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@ import (
)

func TestContactStatusChanged(t *testing.T) {
ctx, rt, db, _ := testsuite.Get()
ctx, rt, _, _ := testsuite.Get()

defer testsuite.Reset(testsuite.ResetAll)

// make sure cathyID contact is active
db.Exec(`UPDATE contacts_contact SET status = 'A' WHERE id = $1`, testdata.Cathy.ID)
defer testsuite.Reset(testsuite.ResetData)

tcs := []handlers.TestCase{
{
Expand Down
9 changes: 0 additions & 9 deletions core/handlers/contact_urns_changed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package handlers_test

import (
"testing"
"time"

"github.com/nyaruka/gocommon/urns"
"github.com/nyaruka/goflow/flows"
Expand All @@ -20,8 +19,6 @@ func TestContactURNsChanged(t *testing.T) {
// add a URN to george that cathy will steal
testdata.InsertContactURN(db, testdata.Org1, testdata.George, urns.URN("tel:+12065551212"), 100)

now := time.Now()

tcs := []handlers.TestCase{
{
Actions: handlers.ContactActionMap{
Expand Down Expand Up @@ -55,12 +52,6 @@ func TestContactURNsChanged(t *testing.T) {
Args: []interface{}{testdata.George.ID},
Count: 1,
},
// two contacts updated, both cathy and evan since their URNs changed
{
SQL: "select count(*) from contacts_contact where modified_on > $1",
Args: []interface{}{now},
Count: 2,
},
},
},
}
Expand Down
35 changes: 35 additions & 0 deletions core/handlers/flow_entered.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package handlers

import (
"context"

"github.com/nyaruka/goflow/flows"
"github.com/nyaruka/goflow/flows/events"
"github.com/nyaruka/mailroom/core/hooks"
"github.com/nyaruka/mailroom/core/models"
"github.com/nyaruka/mailroom/runtime"

"github.com/jmoiron/sqlx"
"github.com/sirupsen/logrus"
)

func init() {
models.RegisterEventHandler(events.TypeFlowEntered, handleFlowEntered)
}

func handleFlowEntered(ctx context.Context, rt *runtime.Runtime, tx *sqlx.Tx, oa *models.OrgAssets, scene *models.Scene, e flows.Event) error {
event := e.(*events.FlowEnteredEvent)

logrus.WithFields(logrus.Fields{
"contact_uuid": scene.ContactUUID(),
"session_id": scene.SessionID(),
"flow_name": event.Flow.Name,
"flow_uuid": event.Flow.UUID,
}).Debug("flow entered")

// we've potentially changed contact flow history.. only way to be sure would be loading contacts with their
// flow history, but not sure that is worth it given how likely we are to be updating modified_on anyway
scene.AppendToEventPreCommitHook(hooks.ContactModifiedHook, event)

return nil
}
42 changes: 42 additions & 0 deletions core/handlers/flow_entered_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package handlers_test

import (
"testing"

"github.com/nyaruka/goflow/flows"
"github.com/nyaruka/goflow/flows/actions"
"github.com/nyaruka/mailroom/core/handlers"
"github.com/nyaruka/mailroom/testsuite"
"github.com/nyaruka/mailroom/testsuite/testdata"
"github.com/stretchr/testify/assert"
)

func TestFlowEntered(t *testing.T) {
ctx, rt, _, _ := testsuite.Get()

defer testsuite.Reset(testsuite.ResetAll)

oa := testdata.Org1.Load(rt)

flow, err := oa.FlowByID(testdata.PickANumber.ID)
assert.NoError(t, err)

tcs := []handlers.TestCase{
{
Actions: handlers.ContactActionMap{
testdata.Cathy: []flows.Action{
actions.NewEnterFlow(handlers.NewActionUUID(), flow.Reference(), false),
},
},
SQLAssertions: []handlers.SQLAssertion{
{
SQL: `select count(*) from contacts_contact where current_flow_id = $1`,
Args: []interface{}{flow.ID()},
Count: 1,
},
},
},
}

handlers.RunTestCases(t, ctx, rt, tcs)
}
Loading

0 comments on commit 79f0600

Please sign in to comment.