-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
63 lines (48 loc) · 1.44 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
63
package main
import (
"github.com/joho/godotenv"
"github.com/ufcg-lsd/arrebol-pb-worker/utils"
"github.com/ufcg-lsd/arrebol-pb-worker/worker"
"log"
"os"
)
const (
ConfFilePathKey = "CONF_FILE_PATH"
ServerEndpointKey = "SERVER_ENDPOINT"
)
func generateKeys(workerId string) {
log.Println("Starting to gen rsa key pair with workerid: " + workerId)
utils.GenAccessKeys(workerId)
}
func main() {
err := godotenv.Load()
if err != nil {
log.Println("No .env file found")
}
startWorker()
}
func startWorker() {
// This is the default work behavior implementation.
// Its core stands for executing one task at a time.
log.Println("Starting reading configuration process")
file, err := os.Open(os.Getenv(ConfFilePathKey))
if err != nil {
log.Fatal("Error on opening configuration file", err.Error())
}
defer file.Close()
workerInstance := worker.ParseWorkerConfiguration(file)
serverEndpoint := os.Getenv(ServerEndpointKey)
//before join the server, the worker must generate the keys
generateKeys(workerInstance.Id)
for {
task, err := workerInstance.GetTask(serverEndpoint)
if err != nil {
//it will force the worker to Join again, if the error has occurred because of
//authentication issues. This is a work arround while the system doesn't have
//its own Error module that will allow it to identify the error type.
workerInstance.Join(serverEndpoint)
continue
}
workerInstance.ExecTask(task, serverEndpoint)
}
}