Skip to content

Commit d15d3b6

Browse files
committed
Rename functions to executor, correct log for duration from int to string
Signed-off-by: Alex Ellis <[email protected]>
1 parent 8bcd840 commit d15d3b6

File tree

6 files changed

+23
-18
lines changed

6 files changed

+23
-18
lines changed

Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
FROM golang:1.9.1
1+
FROM golang:1.9.4
2+
23
RUN mkdir -p /go/src/github.com/openfaas-incubator/of-watchdog
34
WORKDIR /go/src/github.com/openfaas-incubator/of-watchdog
45

56
COPY main.go .
67
COPY config config
7-
COPY functions functions
8+
COPY executor executor
89

910
# Run a gofmt and exclude all vendored code.
1011
RUN test -z "$(gofmt -l $(find . -type f -name '*.go' -not -path "./vendor/*"))"

functions/afterburn_runner.go renamed to executor/afterburn_runner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package functions
1+
package executor
22

33
import (
44
"bufio"

functions/http_runner.go renamed to executor/http_runner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package functions
1+
package executor
22

33
import (
44
"io"

functions/serializing_fork_runner.go renamed to executor/serializing_fork_runner.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package functions
1+
package executor
22

33
import (
44
"io"
@@ -44,19 +44,19 @@ func serializeFunction(req FunctionRequest, f *SerializingForkFunctionRunner) (*
4444

4545
var timer *time.Timer
4646
if f.ExecTimeout > time.Millisecond*0 {
47-
log.Println("Started a timer.")
4847

4948
timer = time.NewTimer(f.ExecTimeout)
5049
go func() {
5150
<-timer.C
5251

53-
log.Printf("Function was killed by ExecTimeout: %s\n", f.ExecTimeout)
52+
log.Printf("Function was killed by ExecTimeout: %s\n", f.ExecTimeout.String())
5453
killErr := cmd.Process.Kill()
5554
if killErr != nil {
5655
log.Println("Error killing function due to ExecTimeout", killErr)
5756
}
5857
}()
5958
}
59+
6060
if timer != nil {
6161
defer timer.Stop()
6262
}

functions/streaming_runner.go renamed to executor/streaming_runner.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package functions
1+
package executor
22

33
import (
44
"fmt"
@@ -43,14 +43,18 @@ func (f *ForkFunctionRunner) Run(req FunctionRequest) error {
4343
go func() {
4444
<-timer.C
4545

46-
fmt.Printf("Function was killed by ExecTimeout: %d\n", f.ExecTimeout)
46+
log.Printf("Function was killed by ExecTimeout: %s\n", f.ExecTimeout.String())
4747
killErr := cmd.Process.Kill()
4848
if killErr != nil {
4949
fmt.Println("Error killing function due to ExecTimeout", killErr)
5050
}
5151
}()
5252
}
5353

54+
if timer != nil {
55+
defer timer.Stop()
56+
}
57+
5458
if req.InputReader != nil {
5559
defer req.InputReader.Close()
5660
cmd.Stdin = req.InputReader

main.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"strings"
1111

1212
"github.com/openfaas-incubator/of-watchdog/config"
13-
"github.com/openfaas-incubator/of-watchdog/functions"
13+
"github.com/openfaas-incubator/of-watchdog/executor"
1414
)
1515

1616
func main() {
@@ -78,7 +78,7 @@ func lock() error {
7878
func makeAfterBurnRequestHandler(watchdogConfig config.WatchdogConfig) func(http.ResponseWriter, *http.Request) {
7979

8080
commandName, arguments := watchdogConfig.Process()
81-
functionInvoker := functions.AfterBurnFunctionRunner{
81+
functionInvoker := executor.AfterBurnFunctionRunner{
8282
Process: commandName,
8383
ProcessArgs: arguments,
8484
}
@@ -88,7 +88,7 @@ func makeAfterBurnRequestHandler(watchdogConfig config.WatchdogConfig) func(http
8888

8989
return func(w http.ResponseWriter, r *http.Request) {
9090

91-
req := functions.FunctionRequest{
91+
req := executor.FunctionRequest{
9292
Process: commandName,
9393
ProcessArgs: arguments,
9494
InputReader: r.Body,
@@ -109,7 +109,7 @@ func makeAfterBurnRequestHandler(watchdogConfig config.WatchdogConfig) func(http
109109
}
110110

111111
func makeSerializingForkRequestHandler(watchdogConfig config.WatchdogConfig) func(http.ResponseWriter, *http.Request) {
112-
functionInvoker := functions.SerializingForkFunctionRunner{
112+
functionInvoker := executor.SerializingForkFunctionRunner{
113113
ExecTimeout: watchdogConfig.ExecTimeout,
114114
}
115115

@@ -122,7 +122,7 @@ func makeSerializingForkRequestHandler(watchdogConfig config.WatchdogConfig) fun
122122
}
123123

124124
commandName, arguments := watchdogConfig.Process()
125-
req := functions.FunctionRequest{
125+
req := executor.FunctionRequest{
126126
Process: commandName,
127127
ProcessArgs: arguments,
128128
InputReader: r.Body,
@@ -140,7 +140,7 @@ func makeSerializingForkRequestHandler(watchdogConfig config.WatchdogConfig) fun
140140
}
141141

142142
func makeForkRequestHandler(watchdogConfig config.WatchdogConfig) func(http.ResponseWriter, *http.Request) {
143-
functionInvoker := functions.ForkFunctionRunner{
143+
functionInvoker := executor.ForkFunctionRunner{
144144
ExecTimeout: watchdogConfig.ExecTimeout,
145145
}
146146

@@ -153,7 +153,7 @@ func makeForkRequestHandler(watchdogConfig config.WatchdogConfig) func(http.Resp
153153
}
154154

155155
commandName, arguments := watchdogConfig.Process()
156-
req := functions.FunctionRequest{
156+
req := executor.FunctionRequest{
157157
Process: commandName,
158158
ProcessArgs: arguments,
159159
InputReader: r.Body,
@@ -196,7 +196,7 @@ func getEnvironment(r *http.Request) []string {
196196

197197
func makeHTTPRequestHandler(watchdogConfig config.WatchdogConfig) func(http.ResponseWriter, *http.Request) {
198198
commandName, arguments := watchdogConfig.Process()
199-
functionInvoker := functions.HTTPFunctionRunner{
199+
functionInvoker := executor.HTTPFunctionRunner{
200200
Process: commandName,
201201
ProcessArgs: arguments,
202202
}
@@ -206,7 +206,7 @@ func makeHTTPRequestHandler(watchdogConfig config.WatchdogConfig) func(http.Resp
206206

207207
return func(w http.ResponseWriter, r *http.Request) {
208208

209-
req := functions.FunctionRequest{
209+
req := executor.FunctionRequest{
210210
Process: commandName,
211211
ProcessArgs: arguments,
212212
InputReader: r.Body,

0 commit comments

Comments
 (0)