mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-22 17:31:03 +01:00
@@ -1,6 +1,8 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crawlab/database"
|
||||
"crawlab/entity"
|
||||
"encoding/json"
|
||||
"github.com/apex/log"
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user