Skip to content

Commit

Permalink
Add new config options for webhooks
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Jan 8, 2020
1 parent 3c0d8bc commit 26792a3
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 15 deletions.
22 changes: 14 additions & 8 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ type Config struct {

RetryPendingMessages bool `help:"whether to requeue pending messages older than five minutes to retry"`

WebhooksTimeout int `help:"the timeout in seconds for webhook calls from engine"`
SMTPServer string `help:"the smtp configuration for sending emails ex: smtp://user%40password@server:port/?from=foo%40gmail.com"`
MaxStepsPerSprint int `help:"the maximum number of steps allowed per engine sprint"`
MaxValueLength int `help:"the maximum size in characters for contact field values and run result values"`
WebhooksTimeout int `help:"the timeout in milliseconds for webhook calls from engine"`
WebhooksMaxRetries int `help:"the number of times to retry a failed webhook call"`
WebhooksInitialBackoff int `help:"the initial backoff in milliseconds when retrying a failed webhook call"`
WebhooksBackoffJitter float64 `help:"the amount of jitter to apply to backoff times"`
SMTPServer string `help:"the smtp configuration for sending emails ex: smtp://user%40password@server:port/?from=foo%40gmail.com"`
MaxStepsPerSprint int `help:"the maximum number of steps allowed per engine sprint"`
MaxValueLength int `help:"the maximum size in characters for contact field values and run result values"`

LibratoUsername string `help:"the username that will be used to authenticate to Librato"`
LibratoToken string `help:"the token that will be used to authenticate to Librato"`
Expand Down Expand Up @@ -61,10 +64,13 @@ func NewMailroomConfig() *Config {
LogLevel: "error",
Version: "Dev",

WebhooksTimeout: 15,
SMTPServer: "",
MaxStepsPerSprint: 100,
MaxValueLength: 640,
WebhooksTimeout: 15000,
WebhooksMaxRetries: 2,
WebhooksInitialBackoff: 5000,
WebhooksBackoffJitter: 0.5,
SMTPServer: "",
MaxStepsPerSprint: 100,
MaxValueLength: 640,

S3Endpoint: "https://s3.amazonaws.com",
S3Region: "us-east-1",
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ require (
github.com/mattn/go-sqlite3 v1.10.0 // indirect
github.com/nyaruka/ezconf v0.2.1
github.com/nyaruka/gocommon v1.1.1
github.com/nyaruka/goflow v0.64.0
github.com/nyaruka/goflow v0.64.1
github.com/nyaruka/librato v1.0.0
github.com/nyaruka/logrus_sentry v0.8.2-0.20190129182604-c2962b80ba7d
github.com/nyaruka/null v1.2.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ github.com/nyaruka/ezconf v0.2.1 h1:TDXWoqjqYya1uhou1mAJZg7rgFYL98EB0Tb3+BWtUh0=
github.com/nyaruka/ezconf v0.2.1/go.mod h1:ey182kYkw2MIi4XiWe1FR/mzI33WCmTWuceDYYxgnQw=
github.com/nyaruka/gocommon v1.1.1 h1:RnQ+kMzN1lA+W0NpkBDd0mGU3UqadJygR3SMpITMYTQ=
github.com/nyaruka/gocommon v1.1.1/go.mod h1:QbdU2J9WBsqBmeZRuwndf2f6O7rD7mkC0bGn5UNnwjI=
github.com/nyaruka/goflow v0.64.0 h1:rKrm83laauEOlRkA5tPSq0rP4yPP87XNR6ZYvyzKkSA=
github.com/nyaruka/goflow v0.64.0/go.mod h1:fb6eGAXiTL2hjbzMpXwSIlNx0O4IsR9XBunXBN+8pWM=
github.com/nyaruka/goflow v0.64.1 h1:tAG4HDFh6h05SKvGZr0a8jimih65t9bDHfRjhfECd/c=
github.com/nyaruka/goflow v0.64.1/go.mod h1:fb6eGAXiTL2hjbzMpXwSIlNx0O4IsR9XBunXBN+8pWM=
github.com/nyaruka/librato v1.0.0 h1:Vznj9WCeC1yZXbBYyYp40KnbmXLbEkjKmHesV/v2SR0=
github.com/nyaruka/librato v1.0.0/go.mod h1:pkRNLFhFurOz0QqBz6/DuTFhHHxAubWxs4Jx+J7yUgg=
github.com/nyaruka/logrus_sentry v0.8.2-0.20190129182604-c2962b80ba7d h1:hyp9u36KIwbTCo2JAJ+TuJcJBc+UZzEig7RI/S5Dvkc=
Expand Down
8 changes: 6 additions & 2 deletions goflow/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,14 @@ func webhooksHTTP() (*http.Client, *httpx.RetryConfig) {

webhooksHTTPClient = &http.Client{
Transport: t,
Timeout: time.Duration(config.Mailroom.WebhooksTimeout) * time.Second,
Timeout: time.Duration(config.Mailroom.WebhooksTimeout) * time.Millisecond,
}

webhooksHTTPRetries = httpx.NewRetryDelays(3, 10)
webhooksHTTPRetries = httpx.NewExponentialRetries(
time.Duration(config.Mailroom.WebhooksInitialBackoff)*time.Millisecond,
config.Mailroom.WebhooksMaxRetries,
config.Mailroom.WebhooksBackoffJitter,
)
})
return webhooksHTTPClient, webhooksHTTPRetries
}
Expand Down
2 changes: 1 addition & 1 deletion models/classifiers.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const (
// Register a classification service factory with the engine
func init() {
httpClient := &http.Client{Timeout: time.Duration(15 * time.Second)}
httpRetries := httpx.NewRetryDelays(3, 10)
httpRetries := httpx.NewFixedRetries(3, 10)

goflow.RegisterClassificationServiceFactory(
func(session flows.Session, classifier *flows.Classifier) (flows.ClassificationService, error) {
Expand Down
2 changes: 1 addition & 1 deletion models/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
func init() {
// give airtime transfers an extra long timeout
airtimeHTTPClient := &http.Client{Timeout: time.Duration(120 * time.Second)}
airtimeHTTPRetries := httpx.NewRetryDelays(5, 10)
airtimeHTTPRetries := httpx.NewFixedRetries(5, 10)

goflow.RegisterEmailServiceFactory(
func(session flows.Session) (flows.EmailService, error) {
Expand Down

0 comments on commit 26792a3

Please sign in to comment.