-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.go
56 lines (50 loc) · 1.05 KB
/
server.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
package machinery
import (
"github.com/RichardKnop/machinery/v1"
"github.com/RichardKnop/machinery/v1/config"
)
func NewServer(tasks map[string]interface{}, configPaths ...interface{}) (*Server, error) {
s := &Server{}
err := s.ParseConfig(configPaths...)
if err != nil {
return s, err
}
err = s.newServer()
if err != nil {
return s, err
}
if tasks != nil {
err = s.RegisterTasks(tasks)
}
return s, err
}
type Server struct {
config *config.Config
*machinery.Server
}
func (s *Server) ParseConfig(configPaths ...interface{}) (err error) {
var configPath string
if len(configPaths) > 0 {
switch c := configPaths[0].(type) {
case string:
configPath = c
case config.Config:
s.config = &c
return
case *config.Config:
s.config = c
return
}
}
if len(configPath) > 0 {
s.config, err = config.NewFromYaml(configPath, true)
return
}
s.config, err = config.NewFromEnvironment()
return
}
// newServer Create server instance
func (s *Server) newServer() (err error) {
s.Server, err = machinery.NewServer(s.config)
return
}