Skip to content

Commit

Permalink
Merge pull request crawlab-team#281 from wo10378931/develop
Browse files Browse the repository at this point in the history
fix 代码遗漏
  • Loading branch information
wo10378931 authored Oct 28, 2019
2 parents 7b01e65 + 965553b commit 818d714
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions backend/utils/helpers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package utils

import (
"context"
"crawlab/database"
"crawlab/entity"
"encoding/json"
"github.com/apex/log"
Expand Down Expand Up @@ -40,3 +42,22 @@ func Close(c io.Closer) {
log.WithError(err).Error("关闭资源文件失败。")
}
}

func Pub(channel string, msg entity.NodeMessage) error {
if _, err := database.RedisClient.Publish(channel, GetJson(msg)); err != nil {
log.Errorf("publish redis error: %s", err.Error())
debug.PrintStack()
return err
}
return nil
}

func Sub(channel string, consume database.ConsumeFunc) error {
ctx := context.Background()
if err := database.RedisClient.Subscribe(ctx, consume, channel); err != nil {
log.Errorf("subscribe redis error: %s", err.Error())
debug.PrintStack()
return err
}
return nil
}

0 comments on commit 818d714

Please sign in to comment.