mirror of
https://github.com/openfaas/faas.git
synced 2025-06-19 04:26:35 +00:00
Vendor new queue-worker version
Introduces 0.4.6 of queue-worker - see upstream repo for changes. Signed-off-by: Alex Ellis (VMware) <alexellis2@gmail.com>
This commit is contained in:
16
gateway/vendor/github.com/openfaas/nats-queue-worker/.DEREK.yml
generated
vendored
Normal file
16
gateway/vendor/github.com/openfaas/nats-queue-worker/.DEREK.yml
generated
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
maintainers:
|
||||
- alexellis
|
||||
- rgee0
|
||||
- johnmccabe
|
||||
- jockdarock
|
||||
- ericstoekl
|
||||
- austinfrey
|
||||
- itscaro
|
||||
- rorpage
|
||||
- kenfdev
|
||||
- BurtonR
|
||||
|
||||
features:
|
||||
- dco_check
|
||||
- comments
|
||||
|
35
gateway/vendor/github.com/openfaas/nats-queue-worker/.github/ISSUE_TEMPLATE.md
generated
vendored
Normal file
35
gateway/vendor/github.com/openfaas/nats-queue-worker/.github/ISSUE_TEMPLATE.md
generated
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
<!--- Provide a general summary of the issue in the Title above -->
|
||||
|
||||
## Expected Behaviour
|
||||
<!--- If you're describing a bug, tell us what should happen -->
|
||||
<!--- If you're suggesting a change/improvement, tell us how it should work -->
|
||||
|
||||
## Current Behaviour
|
||||
<!--- If describing a bug, tell us what happens instead of the expected behavior -->
|
||||
<!--- If suggesting a change/improvement, explain the difference from current behavior -->
|
||||
|
||||
## Possible Solution
|
||||
<!--- Not obligatory, but suggest a fix/reason for the bug, -->
|
||||
<!--- or ideas how to implement the addition or change -->
|
||||
|
||||
## Steps to Reproduce (for bugs)
|
||||
<!--- Provide a link to a live example, or an unambiguous set of steps to -->
|
||||
<!--- reproduce this bug. Include code to reproduce, if relevant -->
|
||||
1.
|
||||
2.
|
||||
3.
|
||||
4.
|
||||
|
||||
## Context
|
||||
<!--- How has this issue affected you? What are you trying to accomplish? -->
|
||||
<!--- Providing context helps us come up with a solution that is most useful in the real world -->
|
||||
|
||||
## Your Environment
|
||||
<!--- Include as many relevant details about the environment you experienced the bug in -->
|
||||
* Docker version `docker version` (e.g. Docker 17.0.05 ):
|
||||
|
||||
* Are you using Docker Swarm or Kubernetes (FaaS-netes)?
|
||||
|
||||
* Operating System and version (e.g. Linux, Windows, MacOS):
|
||||
|
||||
* Link to your project or a code example to reproduce issue:
|
31
gateway/vendor/github.com/openfaas/nats-queue-worker/.github/PULL_REQUEST_TEMPLATE.md
generated
vendored
Normal file
31
gateway/vendor/github.com/openfaas/nats-queue-worker/.github/PULL_REQUEST_TEMPLATE.md
generated
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
<!--- Provide a general summary of your changes in the Title above -->
|
||||
|
||||
## Description
|
||||
<!--- Describe your changes in detail -->
|
||||
|
||||
## Motivation and Context
|
||||
<!--- Why is this change required? What problem does it solve? -->
|
||||
<!--- If it fixes an open issue, please link to the issue here. -->
|
||||
- [ ] I have raised an issue to propose this change ([required](https://github.com/openfaas/faas/blob/master/CONTRIBUTING.md))
|
||||
|
||||
## How Has This Been Tested?
|
||||
<!--- Please describe in detail how you tested your changes. -->
|
||||
<!--- Include details of your testing environment, and the tests you ran to -->
|
||||
<!--- see how your change affects other areas of the code, etc. -->
|
||||
|
||||
## Types of changes
|
||||
<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->
|
||||
- [ ] Bug fix (non-breaking change which fixes an issue)
|
||||
- [ ] New feature (non-breaking change which adds functionality)
|
||||
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
|
||||
|
||||
## Checklist:
|
||||
<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
|
||||
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->
|
||||
- [ ] My code follows the code style of this project.
|
||||
- [ ] My change requires a change to the documentation.
|
||||
- [ ] I have updated the documentation accordingly.
|
||||
- [ ] I've read the [CONTRIBUTION](https://github.com/openfaas/faas/blob/master/CONTRIBUTING.md) guide
|
||||
- [ ] I have signed-off my commits with `git commit -s`
|
||||
- [ ] I have added tests to cover my changes.
|
||||
- [ ] All new and existing tests passed.
|
1
gateway/vendor/github.com/openfaas/nats-queue-worker/.gitignore
generated
vendored
1
gateway/vendor/github.com/openfaas/nats-queue-worker/.gitignore
generated
vendored
@ -15,3 +15,4 @@
|
||||
.idea
|
||||
.DS_Store
|
||||
|
||||
nats-queue-worker
|
||||
|
23
gateway/vendor/github.com/openfaas/nats-queue-worker/.travis.yml
generated
vendored
23
gateway/vendor/github.com/openfaas/nats-queue-worker/.travis.yml
generated
vendored
@ -4,14 +4,29 @@ language: go
|
||||
|
||||
go:
|
||||
- 1.9.x
|
||||
install:
|
||||
- echo "Please don't go get"
|
||||
|
||||
services:
|
||||
- docker
|
||||
|
||||
before_script:
|
||||
- curl -sSL test.docker.com | sudo -E sh
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- docker-ce
|
||||
|
||||
install:
|
||||
- echo "Please don't go get"
|
||||
|
||||
script:
|
||||
- cd queue-worker && ./build.sh
|
||||
|
||||
after_success:
|
||||
- if [ ! -z "$TRAVIS_TAG" ] ; then
|
||||
|
||||
if [ -z $DOCKER_NS ] ; then
|
||||
export DOCKER_NS=functions;
|
||||
fi
|
||||
|
||||
docker tag $DOCKER_NS/queue-worker:latest-dev $DOCKER_NS/queue-worker:$TRAVIS_TAG;
|
||||
echo $DOCKER_PASSWORD | docker login -u=$DOCKER_USERNAME --password-stdin;
|
||||
docker push $DOCKER_NS/queue-worker:$TRAVIS_TAG;
|
||||
fi
|
@ -1,14 +1,20 @@
|
||||
FROM golang:1.9.2-alpine as golang
|
||||
FROM golang:1.9.7-alpine as golang
|
||||
WORKDIR /go/src/github.com/openfaas/nats-queue-worker
|
||||
|
||||
COPY vendor vendor
|
||||
COPY handler handler
|
||||
COPY main.go .
|
||||
|
||||
RUN go test -v ./handler/
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .
|
||||
|
||||
FROM alpine:3.7
|
||||
RUN apk add --no-cache ca-certificates
|
||||
WORKDIR /root/
|
||||
|
||||
RUN addgroup -S app \
|
||||
&& adduser -S -g app app \
|
||||
&& apk add --no-cache ca-certificates
|
||||
|
||||
WORKDIR /home/app
|
||||
|
||||
EXPOSE 8080
|
||||
ENV http_proxy ""
|
||||
@ -16,4 +22,7 @@ ENV https_proxy ""
|
||||
|
||||
COPY --from=golang /go/src/github.com/openfaas/nats-queue-worker/app .
|
||||
|
||||
RUN chown -R app:app ./
|
||||
|
||||
USER app
|
||||
CMD ["./app"]
|
@ -1,14 +1,19 @@
|
||||
FROM golang:1.9.2-alpine as golang
|
||||
FROM golang:1.9.7-alpine as golang
|
||||
WORKDIR /go/src/github.com/openfaas/nats-queue-worker
|
||||
|
||||
COPY vendor vendor
|
||||
COPY handler handler
|
||||
COPY main.go .
|
||||
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .
|
||||
|
||||
FROM alpine:3.7
|
||||
RUN apk add --no-cache ca-certificates
|
||||
WORKDIR /root/
|
||||
|
||||
RUN addgroup -S app \
|
||||
&& adduser -S -g app app \
|
||||
&& apk add --no-cache ca-certificates
|
||||
|
||||
WORKDIR /home/app
|
||||
|
||||
EXPOSE 8080
|
||||
ENV http_proxy ""
|
||||
@ -16,4 +21,7 @@ ENV https_proxy ""
|
||||
|
||||
COPY --from=golang /go/src/github.com/openfaas/nats-queue-worker/app .
|
||||
|
||||
RUN chown -R app:app ./
|
||||
|
||||
USER app
|
||||
CMD ["./app"]
|
50
gateway/vendor/github.com/openfaas/nats-queue-worker/Gopkg.lock
generated
vendored
Normal file
50
gateway/vendor/github.com/openfaas/nats-queue-worker/Gopkg.lock
generated
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
|
||||
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/gogo/protobuf"
|
||||
packages = [
|
||||
"gogoproto",
|
||||
"proto",
|
||||
"protoc-gen-gogo/descriptor"
|
||||
]
|
||||
revision = "1adfc126b41513cc696b209667c8656ea7aac67c"
|
||||
version = "v1.0.0"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/nats-io/go-nats"
|
||||
packages = [
|
||||
".",
|
||||
"encoders/builtin",
|
||||
"util"
|
||||
]
|
||||
revision = "062418ea1c2181f52dc0f954f6204370519a868b"
|
||||
version = "v1.5.0"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/nats-io/go-nats-streaming"
|
||||
packages = [
|
||||
".",
|
||||
"pb"
|
||||
]
|
||||
revision = "e15a53f85e4932540600a16b56f6c4f65f58176f"
|
||||
version = "v0.4.0"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/nats-io/nuid"
|
||||
packages = ["."]
|
||||
revision = "289cccf02c178dc782430d534e3c1f5b72af807f"
|
||||
version = "v1.0.0"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/openfaas/faas"
|
||||
packages = ["gateway/queue"]
|
||||
revision = "81334141832d6c4fc9b78e6b5e17e5330eca7606"
|
||||
version = "0.8.2"
|
||||
|
||||
[solve-meta]
|
||||
analyzer-name = "dep"
|
||||
analyzer-version = 1
|
||||
inputs-digest = "fb873f03ba109e6e479b9133d610f50d7fd6cbcdc0fe7dcf947ae70a1eade465"
|
||||
solver-name = "gps-cdcl"
|
||||
solver-version = 1
|
38
gateway/vendor/github.com/openfaas/nats-queue-worker/Gopkg.toml
generated
vendored
Normal file
38
gateway/vendor/github.com/openfaas/nats-queue-worker/Gopkg.toml
generated
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
# Gopkg.toml example
|
||||
#
|
||||
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
|
||||
# for detailed Gopkg.toml documentation.
|
||||
#
|
||||
# required = ["github.com/user/thing/cmd/thing"]
|
||||
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
|
||||
#
|
||||
# [[constraint]]
|
||||
# name = "github.com/user/project"
|
||||
# version = "1.0.0"
|
||||
#
|
||||
# [[constraint]]
|
||||
# name = "github.com/user/project2"
|
||||
# branch = "dev"
|
||||
# source = "github.com/myfork/project2"
|
||||
#
|
||||
# [[override]]
|
||||
# name = "github.com/x/y"
|
||||
# version = "2.4.0"
|
||||
#
|
||||
# [prune]
|
||||
# non-go = false
|
||||
# go-tests = true
|
||||
# unused-packages = true
|
||||
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/nats-io/go-nats-streaming"
|
||||
version = "0.4.0"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/openfaas/faas"
|
||||
version = "0.8.2"
|
||||
|
||||
[prune]
|
||||
go-tests = true
|
||||
unused-packages = true
|
9
gateway/vendor/github.com/openfaas/nats-queue-worker/Makefile
generated
vendored
Normal file
9
gateway/vendor/github.com/openfaas/nats-queue-worker/Makefile
generated
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
TAG?=latest
|
||||
|
||||
build:
|
||||
docker build --build-arg http_proxy="${http_proxy}" --build-arg https_proxy="${https_proxy}" -t functions/queue-worker:$(TAG) .
|
||||
|
||||
push:
|
||||
docker push functions/queue-worker:$(TAG)
|
||||
|
||||
all: build
|
2
gateway/vendor/github.com/openfaas/nats-queue-worker/README.md
generated
vendored
2
gateway/vendor/github.com/openfaas/nats-queue-worker/README.md
generated
vendored
@ -6,7 +6,7 @@ This is a queue-worker to enable asynchronous processing of function requests.
|
||||
|
||||
* [Read more in the async guide](https://github.com/openfaas/faas/blob/master/guide/asynchronous.md)
|
||||
|
||||
Hub image: [functions/queue-worker:0.1.1](https://hub.docker.com/r/functions/queue-worker/)
|
||||
Hub image: [functions/queue-worker](https://hub.docker.com/r/functions/queue-worker/)
|
||||
|
||||
License: MIT
|
||||
|
||||
|
@ -9,4 +9,3 @@ fi
|
||||
echo Building functions/queue-worker:$eTAG
|
||||
|
||||
docker build --build-arg http_proxy=$http_proxy -t functions/queue-worker:$eTAG .
|
||||
|
17
gateway/vendor/github.com/openfaas/nats-queue-worker/handler/handler.go
generated
vendored
17
gateway/vendor/github.com/openfaas/nats-queue-worker/handler/handler.go
generated
vendored
@ -15,15 +15,26 @@ type NatsQueue struct {
|
||||
nc stan.Conn
|
||||
}
|
||||
|
||||
type NatsConfig interface {
|
||||
GetClientID() string
|
||||
}
|
||||
|
||||
type DefaultNatsConfig struct {
|
||||
}
|
||||
|
||||
func (DefaultNatsConfig) GetClientID() string {
|
||||
val, _ := os.Hostname()
|
||||
return "faas-publisher-" + val
|
||||
}
|
||||
|
||||
// CreateNatsQueue ready for asynchronous processing
|
||||
func CreateNatsQueue(address string, port int) (*NatsQueue, error) {
|
||||
func CreateNatsQueue(address string, port int, clientConfig NatsConfig) (*NatsQueue, error) {
|
||||
queue1 := NatsQueue{}
|
||||
var err error
|
||||
natsURL := fmt.Sprintf("nats://%s:%d", address, port)
|
||||
log.Printf("Opening connection to %s\n", natsURL)
|
||||
|
||||
val, _ := os.Hostname()
|
||||
clientID := "faas-publisher-" + val
|
||||
clientID := clientConfig.GetClientID()
|
||||
clusterID := "faas-cluster"
|
||||
|
||||
nc, err := stan.Connect(clusterID, clientID, stan.NatsURL(natsURL))
|
||||
|
19
gateway/vendor/github.com/openfaas/nats-queue-worker/handler/handler_test.go
generated
vendored
Normal file
19
gateway/vendor/github.com/openfaas/nats-queue-worker/handler/handler_test.go
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_GetClientID_ContainsHostname(t *testing.T) {
|
||||
c := DefaultNatsConfig{}
|
||||
|
||||
val := c.GetClientID()
|
||||
|
||||
hostname, _ := os.Hostname()
|
||||
if !strings.HasSuffix(val, hostname) {
|
||||
t.Errorf("GetClientID should contain hostname as suffix, got: %s", val)
|
||||
t.Fail()
|
||||
}
|
||||
}
|
@ -98,6 +98,7 @@ func main() {
|
||||
|
||||
req := queue.Request{}
|
||||
unmarshalErr := json.Unmarshal(msg.Data, &req)
|
||||
|
||||
if unmarshalErr != nil {
|
||||
log.Printf("Unmarshal error: %s with data %s", unmarshalErr, msg.Data)
|
||||
return
|
||||
@ -115,12 +116,10 @@ func main() {
|
||||
|
||||
functionURL := fmt.Sprintf("http://%s%s:8080/%s", req.Function, functionSuffix, queryString)
|
||||
|
||||
request, err := http.NewRequest("POST", functionURL, bytes.NewReader(req.Body))
|
||||
request, err := http.NewRequest(http.MethodPost, functionURL, bytes.NewReader(req.Body))
|
||||
defer request.Body.Close()
|
||||
|
||||
for k, v := range req.Header {
|
||||
request.Header[k] = v
|
||||
}
|
||||
copyHeaders(request.Header, &req.Header)
|
||||
|
||||
res, err := client.Do(request)
|
||||
var status int
|
||||
@ -135,7 +134,7 @@ func main() {
|
||||
if req.CallbackURL != nil {
|
||||
log.Printf("Callback to: %s\n", req.CallbackURL.String())
|
||||
|
||||
resultStatusCode, resultErr := postResult(&client, req, functionResult, status)
|
||||
resultStatusCode, resultErr := postResult(&client, res, functionResult, req.CallbackURL.String())
|
||||
if resultErr != nil {
|
||||
log.Println(resultErr)
|
||||
} else {
|
||||
@ -170,7 +169,7 @@ func main() {
|
||||
|
||||
if req.CallbackURL != nil {
|
||||
log.Printf("Callback to: %s\n", req.CallbackURL.String())
|
||||
resultStatusCode, resultErr := postResult(&client, req, functionResult, res.StatusCode)
|
||||
resultStatusCode, resultErr := postResult(&client, res, functionResult, req.CallbackURL.String())
|
||||
if resultErr != nil {
|
||||
log.Println(resultErr)
|
||||
} else {
|
||||
@ -238,18 +237,21 @@ func main() {
|
||||
<-cleanupDone
|
||||
}
|
||||
|
||||
func postResult(client *http.Client, req queue.Request, result []byte, statusCode int) (int, error) {
|
||||
func postResult(client *http.Client, functionRes *http.Response, result []byte, callbackURL string) (int, error) {
|
||||
var reader io.Reader
|
||||
|
||||
if result != nil {
|
||||
reader = bytes.NewReader(result)
|
||||
}
|
||||
|
||||
request, err := http.NewRequest("POST", req.CallbackURL.String(), reader)
|
||||
request, err := http.NewRequest(http.MethodPost, callbackURL, reader)
|
||||
|
||||
copyHeaders(request.Header, &functionRes.Header)
|
||||
|
||||
res, err := client.Do(request)
|
||||
|
||||
if err != nil {
|
||||
return http.StatusBadGateway, fmt.Errorf("error posting result to URL %s %s", req.CallbackURL.String(), err.Error())
|
||||
return http.StatusBadGateway, fmt.Errorf("error posting result to URL %s %s", callbackURL, err.Error())
|
||||
}
|
||||
|
||||
if request.Body != nil {
|
||||
@ -262,6 +264,14 @@ func postResult(client *http.Client, req queue.Request, result []byte, statusCod
|
||||
return res.StatusCode, nil
|
||||
}
|
||||
|
||||
func copyHeaders(destination http.Header, source *http.Header) {
|
||||
for k, v := range *source {
|
||||
vClone := make([]string, len(v))
|
||||
copy(vClone, v)
|
||||
(destination)[k] = vClone
|
||||
}
|
||||
}
|
||||
|
||||
func postReport(client *http.Client, function string, statusCode int, timeTaken float64, gatewayAddress string) (int, error) {
|
||||
req := AsyncReport{
|
||||
FunctionName: function,
|
||||
@ -271,7 +281,7 @@ func postReport(client *http.Client, function string, statusCode int, timeTaken
|
||||
|
||||
targetPostback := "http://" + gatewayAddress + ":8080/system/async-report"
|
||||
reqBytes, _ := json.Marshal(req)
|
||||
request, err := http.NewRequest("POST", targetPostback, bytes.NewReader(reqBytes))
|
||||
request, err := http.NewRequest(http.MethodPost, targetPostback, bytes.NewReader(reqBytes))
|
||||
defer request.Body.Close()
|
||||
|
||||
res, err := client.Do(request)
|
1
gateway/vendor/github.com/openfaas/nats-queue-worker/queue-worker/.gitignore
generated
vendored
1
gateway/vendor/github.com/openfaas/nats-queue-worker/queue-worker/.gitignore
generated
vendored
@ -1 +0,0 @@
|
||||
queue-worker
|
5
gateway/vendor/github.com/openfaas/nats-queue-worker/queue-worker/vendor.conf
generated
vendored
5
gateway/vendor/github.com/openfaas/nats-queue-worker/queue-worker/vendor.conf
generated
vendored
@ -1,5 +0,0 @@
|
||||
github.com/openfaas/faas 4cc299d4c84e7ce10c6a5117e918c5a5b4aeb2ae
|
||||
github.com/nats-io/go-nats-streaming bf8654e90f5296da96eab1e85808eb5c4b7b5541
|
||||
github.com/nats-io/go-nats 34c8842105ac0b69c838a9998a239d482936c466
|
||||
github.com/nats-io/nuid 3cf34f9fca4e88afa9da8eabd75e3326c9941b44
|
||||
github.com/gogo/protobuf dda3e8acadcc9affc16faf33fbb229db78399245
|
Reference in New Issue
Block a user