Update nats-queue-worker package to 0.4.7

This package version supports running OpenFaas on hosts the contain `.`
in their hostname i.e. computer-a.acme.com

Signed-off-by: Edward Wilde <ewilde@gmail.com>
This commit is contained in:
Edward Wilde
2018-06-21 20:30:28 +01:00
committed by Alex Ellis
parent 08d57de1f6
commit e39dbd9584
6 changed files with 37 additions and 6 deletions

View File

@ -17,7 +17,7 @@ install:
- echo "Please don't go get"
script:
- cd queue-worker && ./build.sh
- ./build.sh
after_success:
- if [ ! -z "$TRAVIS_TAG" ] ; then

View File

@ -33,6 +33,10 @@
name = "github.com/openfaas/faas"
version = "0.8.2"
[[constraint]]
name = "github.com/nats-io/go-nats"
version = "v1.5.0"
[prune]
go-tests = true
unused-packages = true

View File

@ -8,6 +8,7 @@ import (
"github.com/nats-io/go-nats-streaming"
"github.com/openfaas/faas/gateway/queue"
"regexp"
)
// NatsQueue queue for work
@ -22,9 +23,11 @@ type NatsConfig interface {
type DefaultNatsConfig struct {
}
var supportedCharacters, _ = regexp.Compile("[^a-zA-Z0-9-_]+")
func (DefaultNatsConfig) GetClientID() string {
val, _ := os.Hostname()
return "faas-publisher-" + val
return getClientId(val)
}
// CreateNatsQueue ready for asynchronous processing
@ -58,3 +61,7 @@ func (q *NatsQueue) Queue(req *queue.Request) error {
return err
}
func getClientId(hostname string) string {
return "faas-publisher-" + supportedCharacters.ReplaceAllString(hostname, "_")
}

View File

@ -17,3 +17,23 @@ func Test_GetClientID_ContainsHostname(t *testing.T) {
t.Fail()
}
}
func TestCreateClientId(t *testing.T) {
clientId := getClientId("computer-a")
expected := "faas-publisher-computer-a"
if clientId != expected {
t.Logf("Expected client id `%s` actual `%s`\n", expected, clientId)
t.Fail()
}
}
func TestCreateClientIdWhenHostHasUnsupportedCharacters(t *testing.T) {
clientId := getClientId("computer-a.acme.com")
expected := "faas-publisher-computer-a_acme_com"
if clientId != expected {
t.Logf("Expected client id `%s` actual `%s`\n", expected, clientId)
t.Fail()
}
}