Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
Signed-off-by: FogDong <dongtianxin.tx@alibaba-inc.com>
  • Loading branch information
FogDong committed Dec 13, 2022
1 parent f4afe6d commit 3b9bbe4
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions pkg/backup/sls/producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (

// Handler is sls config.
type Handler struct {
LogStoreName string
ProjectName string
Producer *producer.Producer
LogStoreName string
ProjectName string
ProducerConfig *producer.ProducerConfig
}

type Callback struct {
Expand All @@ -38,9 +38,9 @@ func NewSLSHandler(config map[string][]byte) (*Handler, error) {
producerConfig.AccessKeySecret = accessKeySecret

return &Handler{
Producer: producer.InitProducer(producerConfig),
LogStoreName: logStoreName,
ProjectName: projectName,
ProducerConfig: producerConfig,
LogStoreName: logStoreName,
ProjectName: projectName,
}, nil
}

Expand All @@ -54,8 +54,9 @@ func (callback *Callback) Success(result *producer.Result) {
// Store is store workflowRun to sls
func (s *Handler) Store(ctx monitorContext.Context, run *v1alpha1.WorkflowRun) error {
ctx.Info("Start Send workflow record to SLS")
s.Producer.Start()
defer s.Producer.SafeClose()
p := producer.InitProducer(s.ProducerConfig)
p.Start()
defer p.SafeClose()

data, err := json.Marshal(run)
if err != nil {
Expand All @@ -65,7 +66,7 @@ func (s *Handler) Store(ctx monitorContext.Context, run *v1alpha1.WorkflowRun) e

callback := &Callback{ctx: ctx}
log := producer.GenerateLog(uint32(time.Now().Unix()), map[string]string{"content": string(data)})
err = s.Producer.SendLogWithCallBack(s.ProjectName, s.LogStoreName, "topic", "", log, callback)
err = p.SendLogWithCallBack(s.ProjectName, s.LogStoreName, "topic", "", log, callback)
if err != nil {
ctx.Error(err, "Send WorkflowRun Content to SLS fail")
return err
Expand Down

0 comments on commit 3b9bbe4

Please sign in to comment.