forked from rancher/agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogress.go
36 lines (32 loc) · 1.03 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
package progress
import (
"fmt"
"github.com/Sirupsen/logrus"
revents "github.com/rancher/event-subscriber/events"
v3 "github.com/rancher/go-rancher/v3"
)
type Progress struct {
Request *revents.Event
Client *v3.RancherClient
}
func (p *Progress) Update(msg string, types string, data map[string]interface{}) {
resp := &v3.Publish{
ResourceId: p.Request.ResourceID,
PreviousIds: []string{p.Request.ID},
ResourceType: p.Request.ResourceType,
Name: p.Request.ReplyTo,
Data: data,
Transitioning: types,
TransitioningMessage: msg,
}
transition := fmt.Sprintf("%s: %s", resp.Transitioning, resp.TransitioningMessage)
logrus.Debugf("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 publishReply(reply *v3.Publish, apiClient *v3.RancherClient) error {
_, err := apiClient.Publish.Create(reply)
return err
}