forked from jeffaco/duplicacy-util
-
Notifications
You must be signed in to change notification settings - Fork 0
/
notify.go
117 lines (99 loc) · 2.24 KB
/
notify.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package main
import (
"errors"
)
func notifyOfStart() error {
var savedError error
for _, notifier := range onStartNotifiers {
if err := notifier.NotifyOfStart(); err != nil {
savedError = err
}
}
return savedError
}
func notifyOfSkip() error {
var savedError error
for _, notifier := range onSkipNotifiers {
if err := notifier.NotifyOfSkip(); err != nil {
savedError = err
}
}
return savedError
}
func notifyOfSuccess() error {
var savedError error
for _, notifier := range onSuccessNotifiers {
if err := notifier.NotifyOfSuccess(); err != nil {
savedError = err
}
}
return savedError
}
func notifyOfFailure() error {
var savedError error
for _, notifier := range onFailureNotifiers {
if err := notifier.NotifyOfFailure(); err != nil {
savedError = err
}
}
return savedError
}
func testNotifications() error {
var savedError error
cmdConfig = "test"
backupTable = []backupRevision{
{
storage: "b2",
chunkTotalCount: "149",
chunkTotalSize: "870,624K",
filesTotalCount: "345",
filesTotalSize: "823,261K",
filesNewCount: "1",
filesNewSize: "7,984K",
chunkNewCount: "6",
chunkNewSize: "8,106K",
chunkNewUploaded: "3,410K",
duration: "9 seconds",
},
{
storage: "azure-direct",
chunkTotalCount: "149",
chunkTotalSize: "870,624K",
filesTotalCount: "345",
filesTotalSize: "823,261K",
filesNewCount: "1",
filesNewSize: "7,984K",
chunkNewCount: "6",
chunkNewSize: "8,106K",
chunkNewUploaded: "3,410K",
duration: "2 seconds",
},
}
copyTable = []copyRevision{
{
storageFrom: "b2",
storageTo: "azure-direct",
chunkTotalCount: "109",
chunkCopyCount: "3",
chunkSkipCount: "106",
duration: "9 seconds",
},
}
// Testing notifications while no notifications are set makes no sense
if len(onFailureNotifiers) == 0 {
return errors.New("Warning: No notifiers are configured")
}
if err := notifyOfStart(); err != nil {
savedError = err
}
if err := notifyOfSkip(); err != nil {
savedError = err
}
if err := notifyOfSuccess(); err != nil {
savedError = err
}
if err := notifyOfFailure(); err != nil {
savedError = err
}
return savedError
}