support attach labels to rule result
This commit is contained in:
@@ -119,6 +119,12 @@ func (r *periodic) execute(ctx context.Context, now time.Time) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Attach labels to feeds.
|
||||
for _, feed := range feeds {
|
||||
feed.Labels = append(feed.Labels, config.labels...)
|
||||
feed.Labels.EnsureSorted()
|
||||
}
|
||||
|
||||
// Notify.
|
||||
r.Dependencies().Out <- &Result{
|
||||
Rule: config.Name,
|
||||
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/glidea/zenfeed/pkg/component"
|
||||
"github.com/glidea/zenfeed/pkg/model"
|
||||
"github.com/glidea/zenfeed/pkg/storage/feed"
|
||||
"github.com/glidea/zenfeed/pkg/storage/feed/block"
|
||||
)
|
||||
@@ -37,6 +38,8 @@ type Config struct {
|
||||
Query string
|
||||
Threshold float32
|
||||
LabelFilters []string
|
||||
Labels map[string]string
|
||||
labels model.Labels
|
||||
|
||||
// Periodic type.
|
||||
EveryDay string // e.g. "00:00~23:59", or "-22:00~7:00" (yesterday 22:00 to today 07:00)
|
||||
@@ -63,6 +66,9 @@ func (c *Config) Validate() error { //nolint:cyclop,gocognit
|
||||
if c.Threshold < 0 || c.Threshold > 1 {
|
||||
return errors.New("threshold must be between 0 and 1")
|
||||
}
|
||||
if len(c.Labels) > 0 {
|
||||
c.labels.FromMap(c.Labels)
|
||||
}
|
||||
if c.EveryDay != "" && c.WatchInterval != 0 {
|
||||
return errors.New("every_day and watch_interval cannot both be set")
|
||||
}
|
||||
|
||||
@@ -101,6 +101,12 @@ func (r *watch) execute(ctx context.Context, start, end time.Time) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Attach labels to feeds.
|
||||
for _, feed := range feeds {
|
||||
feed.Labels = append(feed.Labels, config.labels...)
|
||||
feed.Labels.EnsureSorted()
|
||||
}
|
||||
|
||||
// Split feeds by start time.
|
||||
feedsByStart := make(map[time.Time][]*block.FeedVO) // Start time -> feeds.
|
||||
for _, feed := range feeds {
|
||||
|
||||
@@ -58,6 +58,7 @@ func (c *Config) From(app *config.App) *Config {
|
||||
Query: r.Query,
|
||||
Threshold: r.Threshold,
|
||||
LabelFilters: r.LabelFilters,
|
||||
Labels: r.Labels,
|
||||
EveryDay: r.EveryDay,
|
||||
WatchInterval: time.Duration(r.WatchInterval),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user