-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
101 lines (73 loc) · 2.05 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
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
package main
import (
"fmt"
"strings"
"github.com/reasje/go_discord_thread_saver/internal/metadata"
"github.com/reasje/go_discord_thread_saver/internal/storage"
"github.com/reasje/go_discord_thread_saver/services/bot"
"github.com/reasje/go_discord_thread_saver/services/config"
"github.com/reasje/go_discord_thread_saver/services/ticker"
)
// IDEA: resstructure the project to make it more readable (handle protocols)
// IDEA: handeling failures (retry till success )
func threadKeepAliveBackgroundTask(c chan string) {
for {
m := <-c
if m == metadata.REFRESH {
// if there is no an active ticker running
// then It means
if storage.Ticker != nil {
ticker.StopTicker()
go ticker.StartTicker()
}else{
go ticker.StartTicker()
}
}else {
fmt.Println("Invalid Signal")
}
}
}
func getUserResfreshBackgroundTask(quit chan string) {
for {
var userInput string
fmt.Scanln(&userInput)
userInput = strings.ToLower(userInput)
if userInput == "r" {
fmt.Println("Restating thread keep alive task")
// sc := make(chan os.Signal, 1)
// signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
// <-sc
quit <- metadata.REFRESH
// go threadKeepAliveBackgroundTask()
}
}
}
func main() {
err := config.ReadConfig()
if err != nil {
fmt.Println(err.Error())
}
bot.StartBot()
// NOTE only one channel is used fo controlling app
c := make(chan string)
// keeping the task in the background up and running
go threadKeepAliveBackgroundTask(c)
// keeping the user input task running in the background
go getUserResfreshBackgroundTask(c)
// starts the process
c <- metadata.REFRESH
// for range quitStart{
// // quitValue := <- quitStart
// // quitString := strconv.FormatBool(quitValue)
// quitFinal <- true
// }
// quitValue , ok := <- quitStart
// if ok {
// quitString := strconv.FormatBool(quitValue)
// fmt.Println("**Shutting down* %v *" + quitString)
// quitFinal <- true
// }
// this keeps our threads running
select {}
// }
}