forked from Layer-Edge/light-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
74 lines (60 loc) · 1.47 KB
/
main.go
File metadata and controls
74 lines (60 loc) · 1.47 KB
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
package main
import (
"context"
"fmt"
"log"
"os"
"os/signal"
"sync"
"syscall"
"time"
"github.com/Layer-Edge/light-node/node"
"github.com/Layer-Edge/light-node/utils"
"github.com/joho/godotenv"
)
func Worker(ctx context.Context, wg *sync.WaitGroup, id int) {
defer wg.Done()
for {
select {
case <-ctx.Done():
fmt.Printf("Worker %d is shutting down\n", id)
return
default:
fmt.Printf("Worker %d is running...\n", id)
node.CollectSampleAndVerify()
time.Sleep(5 * time.Second)
}
}
}
func main() {
workDir, _ := os.Getwd()
fmt.Printf("Current working directory: %s\n", workDir)
err := godotenv.Load("./.env")
if err != nil {
altErr := godotenv.Load()
if altErr != nil {
log.Println("Warning: .env file not found, will use default values if needed")
} else {
log.Println("Environment loaded from default location")
}
} else {
log.Println("Environment loaded from ./.env")
}
pubKey, err := utils.GetCompressedPublicKey()
if err != nil {
log.Fatalf("Error getting compressed public key: %v", err)
}
log.Printf("Compressed Public Key: %s", pubKey)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var wg sync.WaitGroup
signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, syscall.SIGABRT, syscall.SIGTERM)
wg.Add(1)
go Worker(ctx, &wg, 1)
<-signalChan
fmt.Println("\nReceived interrupt signal. Shutting down gracefully...")
cancel()
wg.Wait()
fmt.Println("Worker has shut down. Exiting..")
}