-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
62 lines (50 loc) · 1.22 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
package main
import (
"fmt"
"log"
"net/http"
)
// Task represents a unit of work to be performed
type Task struct {
message string
}
// TaskResult holds the result of a task
type TaskResult struct {
application string
status bool
reason string
}
var taskQueue = make(chan Task, 10)
var resultQueue = make(chan TaskResult, 10)
var config, err = readConfig()
// processes tasks from the taskQueue
func Worker(id int) {
for task := range taskQueue {
fmt.Printf("Dispatching task with message: %s", task.message)
go sendDiscordMessage(DiscordPayload{Content: task.message})
go sendSlackMessage(task.message)
}
}
// processes tasks from the resultQueue
func Reporter() {
for result := range resultQueue {
if result.status {
fmt.Printf("Task completed successfully by %s\n", result.application)
} else {
fmt.Printf("Task failed by %s, with reason: %s\n", result.application, result.reason)
}
}
}
func main() {
if err != nil {
log.Fatalf("Failed to read config: %v", err)
}
http.HandleFunc("/webhook", webhookHandler)
fmt.Println("Starting server on :3000...")
numWorkers := 3
for i := 0; i < numWorkers; i++ {
go Worker(i + 1)
}
go Reporter()
log.Fatal(http.ListenAndServe(":8080", nil))
}