-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupd_status.go
44 lines (38 loc) · 1.1 KB
/
upd_status.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
package updaterini
type CheckStatus int
const (
CheckSuccess CheckStatus = iota // no errors
CheckHasErrors // process finished successfully, but with errors
CheckFailure // process interrupted by error
)
type SourceStatus struct {
Source UpdateSource // link to source instance, cast it to base class
Errors []error // source errors
Status CheckStatus // source status
}
func (ss *SourceStatus) appendError(err error, critical bool) {
ss.Errors = append(ss.Errors, err)
if ss.Status == CheckFailure || critical {
ss.Status = CheckFailure
} else {
ss.Status = CheckHasErrors
}
}
type SourceCheckStatus struct {
SourcesStatuses []SourceStatus // sources statuses
Status CheckStatus // sources check status
}
func (scs *SourceCheckStatus) updateSourceCheckStatus() {
hasSuccess := false
for _, source := range scs.SourcesStatuses {
if source.Status != CheckFailure {
hasSuccess = true
}
if scs.Status < source.Status {
scs.Status = source.Status
}
}
if scs.Status == CheckFailure && hasSuccess {
scs.Status = CheckHasErrors
}
}