-
Notifications
You must be signed in to change notification settings - Fork 0
/
workerUtilsCustom.go
149 lines (115 loc) · 3.7 KB
/
workerUtilsCustom.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package main
import (
"bufio"
"encoding/json"
"fmt"
"os"
"strconv"
"time"
"github.com/ditrit/gandalf/core/models"
worker "github.com/ditrit/gandalf/connectors/go"
"github.com/ditrit/shoset/msg"
"github.com/ditrit/gandalf/libraries/goclient"
)
//main : main
func main() {
var major = int64(1)
var minor = int64(0)
fmt.Println("VERSION")
fmt.Println(major)
fmt.Println(minor)
input := bufio.NewScanner(os.Stdin)
input.Scan()
fmt.Println(input.Text())
worker := worker.NewWorker(major, minor)
var inputPayload InputPayload
err := json.Unmarshal([]byte(input.Text()), &inputPayload)
fmt.Println("inputPayload")
fmt.Println(err)
fmt.Println(inputPayload)
worker.RegisterCommandsFuncs("CREATE_FORM", CreateForm)
worker.RegisterCommandsFuncs("SEND_AUTH_MAIL", SendAuthMail)
worker.Run()
}
type InputPayload struct {
TotoKey string
TataKey string
TutuKey string
TitiKey string
EventTypeToPolls []models.EventTypeToPoll
//....
}
func SendAuthMail(clientGandalf *goclient.ClientGandalf, major int64, command msg.Command) int {
fmt.Println("EXECUTE SEND AUTH MAIL 1.0")
return 0
/* var configuration Configuration
mydir, _ := os.Getwd()
file, _ := os.Open(mydir + "/test.json")
decoder := json.NewDecoder(file)
decoder.Decode(&configuration)
var mailPayload mail.MailPayload
err := json.Unmarshal([]byte(command.GetPayload()), &mailPayload)
if err == nil {
clientmail := mail.NewMailClient(configuration.Address, configuration.Port)
auth := clientmail.Auth(mailPayload.Username, mailPayload.Password, configuration.Address)
clientmail.SendAuthMail(mailPayload.Sender, mailPayload.Body, mailPayload.Receivers, auth)
return 0
}
return 1 */
}
func CreateForm(clientGandalf *goclient.ClientGandalf, major int64, command msg.Command) int {
fmt.Println("EXECUTE CREATE FORM 1.0")
for i := 0; i < 100; i++ {
fmt.Println("1.0 : " + strconv.Itoa(i) + "%")
clientGandalf.SendReply(command.GetCommand(), "STATE", command.GetUUID(), map[string]string{"payload": "1.0 : " + strconv.Itoa(i)})
time.Sleep(1 * time.Second)
}
return 0
/* var formPayload form.FormPayload
err := json.Unmarshal([]byte(command.GetPayload()), &formPayload)
if err == nil {
clientFormServer := form.NewFormServer(command.GetUUID(), formPayload, clientGandalf)
go clientFormServer.Run()
return 0
}
return 1
*/
}
/* //CreateApplication : CreateApplication
func CreateApplication(clientGandalf *goclient.ClientGandalf, major, minor int64) {
var configuration Configuration
mydir, _ := os.Getwd()
file, _ := os.Open(mydir + "/test.json")
decoder := json.NewDecoder(file)
decoder.Decode(&configuration)
workerApp := workers.NewWorkerApplication(clientGandalf, major, minor)
//go workerApp.Run()
}
//CreateForm : CreateForm
func CreateForm(clientGandalf *goclient.ClientGandalf, major, minor int64) {
var configuration Configuration
mydir, _ := os.Getwd()
file, _ := os.Open(mydir + "/test.json")
decoder := json.NewDecoder(file)
decoder.Decode(&configuration)
workerForm := workers.NewWorkerForm(clientGandalf, major, minor)
//go workerForm.Run()
}
//SendAuthMail : SendAuthMail
func SendAuthMail(clientGandalf *goclient.ClientGandalf, major, minor int64) {
var configuration Configuration
mydir, _ := os.Getwd()
file, _ := os.Open(mydir + "/test.json")
decoder := json.NewDecoder(file)
decoder.Decode(&configuration)
workerMail := workers.NewWorkerMail(configuration.Address, configuration.Port, clientGandalf, major, minor)
//go workerMail.Run()
} */
//Configuration : Configuration
type Configuration struct {
Address string
Port string
Contact string
Pwd string
Mail string
}