This repository has been archived by the owner on Jun 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 64
/
progress.go
65 lines (60 loc) · 2.09 KB
/
progress.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
package progress
import (
"fmt"
"github.com/Sirupsen/logrus"
revents "github.com/rancher/event-subscriber/events"
"github.com/rancher/go-rancher/v2"
)
type Progress struct {
Request *revents.Event
Client *client.RancherClient
}
func (p *Progress) Update(msg string, types string, data map[string]interface{}) {
resp := &client.Publish{
ResourceId: p.Request.ResourceID,
PreviousIds: []string{p.Request.ID},
ResourceType: p.Request.ResourceType,
Name: p.Request.ReplyTo,
Data: data,
Transitioning: types,
TransitioningMessage: msg,
TransitioningProgress: 0,
}
transition := fmt.Sprintf("%s: %s", resp.Transitioning, resp.TransitioningMessage)
logrus.Infof("Reply: %v, %v, %v:%v, transitioning: %v", p.Request.ID, p.Request.Name, resp.ResourceId, resp.ResourceType, transition)
err := publishReply(resp, p.Client)
if err != nil {
logrus.Error(err)
}
}
func (p *Progress) UpdateWithParent(msg string, types string, data map[string]interface{}, event, parent *revents.Event) {
resp := &client.Publish{
ResourceId: parent.ResourceID,
PreviousIds: []string{parent.ID},
ResourceType: parent.ResourceType,
Name: parent.ReplyTo,
Data: map[string]interface{}{
"resourceId": event.ResourceID,
"previousIds": []string{event.ID},
"resourceType": event.ResourceType,
"name": event.ReplyTo,
"data": data,
"transitioning": types,
"transitioningMessage": msg,
"transitioningProgress": 0,
},
Transitioning: types,
TransitioningMessage: msg,
TransitioningProgress: 0,
}
transition := fmt.Sprintf("%s: %s", resp.Transitioning, resp.TransitioningMessage)
logrus.Infof("Reply: %v, %v, %v:%v, transitioning: %v", p.Request.ID, p.Request.ReplyTo, resp.ResourceId, resp.ResourceType, transition)
err := publishReply(resp, p.Client)
if err != nil {
logrus.Error(err)
}
}
func publishReply(reply *client.Publish, apiClient *client.RancherClient) error {
_, err := apiClient.Publish.Create(reply)
return err
}