This repository has been archived by the owner on Nov 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
62 lines (50 loc) · 1.87 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"os"
"log"
"flag"
"strconv"
"path/filepath"
)
var (
workflow = flag.String("workflow", "/usr/local/vamp/workflow.js", "Path to workflow file.")
httpPort = flag.Int("httpPort", 8080, "HTTP port.")
uiPath = flag.String("uiPath", "./ui/", "Path to UI static content.")
executionPeriod = flag.Int("executionPeriod", -1, "Period between successive executions in seconds (0 if disabled).")
executionTimeout = flag.Int("executionTimeout", -1, "Maximum allowed execution time in seconds (0 if no timeout).")
help = flag.Bool("help", false, "Print usage.")
)
func main() {
log.SetFlags(log.Ldate | log.Ltime | log.LUTC | log.Lmicroseconds | log.Lshortfile)
flag.Parse()
if *help {
flag.Usage()
return
}
uiAbsPath, err := filepath.Abs(*uiPath)
if err != nil {
log.Fatal(err)
}
checkInt(executionPeriod, "VAMP_WORKFLOW_EXECUTION_PERIOD", "Execution period must be specified and it must be equal or greater than 0.")
checkInt(executionTimeout, "VAMP_WORKFLOW_EXECUTION_TIMEOUT", "Execution timeout must be specified and it must be equal or greater than 0.")
log.Println("HTTP port :", *httpPort)
log.Println("HTTP static content path :", uiAbsPath)
log.Println("Workflow file path :", *workflow)
log.Println("Workflow execution period :", *executionPeriod)
log.Println("Workflow execution timeout:", *executionTimeout)
api := &Api{make(chan interface{})}
go run(api, *workflow)
serve(api, *httpPort, uiAbsPath)
}
func checkInt(argument *int, environmentVariable, panic string) {
if *argument < 0 {
number, err := strconv.Atoi(os.Getenv(environmentVariable))
if err != nil {
log.Fatal(panic)
}
*argument = number
if *argument < 0 {
log.Fatal(panic)
}
}
}