-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
64 lines (50 loc) · 1.75 KB
/
Copy pathmain.go
File metadata and controls
64 lines (50 loc) · 1.75 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
package main
import (
"LearnGoNotificationApp/enums"
"LearnGoNotificationApp/models"
"LearnGoNotificationApp/senders"
"LearnGoNotificationApp/utils"
"LearnGoNotificationApp/workers"
"fmt"
"sync"
)
func main() {
fmt.Printf("TestApp is starting...\n")
fmt.Println()
notifications := make(map[string]*models.Person)
notifications["Alex"] = models.NewPerson("Alex", enums.Reminder, enums.NotSent, senders.SmsSender{})
notifications["Chris"] = models.NewPerson("Chris", enums.Blast, enums.NotSent, senders.EmailSender{})
notifications["Prince"] = models.NewPerson("Prince", enums.Blast, enums.NotSent, senders.SmsSender{})
notifications["Albert"] = models.NewPerson("Albert", enums.Reminder, enums.NotSent, senders.EmailSender{})
notifications["Kevin"] = models.NewPerson("Kevin", enums.Reminder, enums.NotSent, senders.SmsSender{})
notificationQueue := make(chan *models.Person)
numWorkers := 3
var wg sync.WaitGroup
for i := 0; i < numWorkers; i++ {
wg.Add(1)
go func() {
defer wg.Done()
workers.NotificationWorker(notificationQueue)
}()
}
// fill the channel
for key, value := range notifications {
fmt.Printf("Queueing notification for %s\n", key)
notificationQueue <- value
}
close(notificationQueue)
wg.Wait()
failed := utils.FilterMap(notifications, func(p *models.Person) bool {
return p.Status == enums.Failed
})
successful := utils.FilterMap(notifications, func(p *models.Person) bool {
return p.Status == enums.Success
})
remaining := utils.FilterMap(notifications, func(p *models.Person) bool {
return p.Status == enums.NotSent
})
fmt.Println()
utils.PrintStatusReport("Failed Outreach", failed)
utils.PrintStatusReport("Successful Outreach", successful)
utils.PrintStatusReport("Remaining Outreach", remaining)
}