notify filter always executes when editing
This commit is contained in:
parent
db5a159469
commit
ac7a3f991b
1 changed files with 22 additions and 4 deletions
26
scraping.go
26
scraping.go
|
@ -63,8 +63,9 @@ func processFilters(filters []Filter, web *Web, watch *Watch, debug bool, schedu
|
||||||
currentFilters = append(currentFilters, filter)
|
currentFilters = append(currentFilters, filter)
|
||||||
}
|
}
|
||||||
|
|
||||||
// collect 'store' filters so we can process them separately at the end
|
// collect 'store' and 'notify' filters so we can process them separately at the end
|
||||||
storeFilters := make([]*Filter, 0)
|
storeFilters := make([]*Filter, 0, 5)
|
||||||
|
notifyFilters := make([]*Filter, 0, 5)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
nextFilters := make([]*Filter, 0, len(currentFilters))
|
nextFilters := make([]*Filter, 0, len(currentFilters))
|
||||||
|
@ -88,6 +89,9 @@ func processFilters(filters []Filter, web *Web, watch *Watch, debug bool, schedu
|
||||||
processedMap[filter.ID] = true
|
processedMap[filter.ID] = true
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if debug && filter.Type == "notify" {
|
||||||
|
notifyFilters = append(notifyFilters, filter)
|
||||||
|
}
|
||||||
if len(filter.Parents) == 0 && !debug {
|
if len(filter.Parents) == 0 && !debug {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -115,6 +119,16 @@ func processFilters(filters []Filter, web *Web, watch *Watch, debug bool, schedu
|
||||||
for _, storeFilter := range storeFilters {
|
for _, storeFilter := range storeFilters {
|
||||||
getFilterResult(filters, storeFilter, watch, web, debug)
|
getFilterResult(filters, storeFilter, watch, web, debug)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// process the notify filters when editing, so it still logs and can put the message in results
|
||||||
|
if debug {
|
||||||
|
for _, nFilter := range notifyFilters {
|
||||||
|
if len(nFilter.Results) == 0 {
|
||||||
|
notifyFilter(filters, nFilter, watch, web, debug)
|
||||||
|
log.Println(nFilter.Results)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getFilterResult(filters []Filter, filter *Filter, watch *Watch, web *Web, debug bool) {
|
func getFilterResult(filters []Filter, filter *Filter, watch *Watch, web *Web, debug bool) {
|
||||||
|
@ -1086,7 +1100,7 @@ func notifyFilter(filters []Filter, filter *Filter, watch *Watch, web *Web, debu
|
||||||
haveResults = true
|
haveResults = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !haveResults {
|
if !debug && !haveResults {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
tmpl, err := template.New("notify").Parse(filter.Var1)
|
tmpl, err := template.New("notify").Parse(filter.Var1)
|
||||||
|
@ -1099,6 +1113,10 @@ func notifyFilter(filters []Filter, filter *Filter, watch *Watch, web *Web, debu
|
||||||
dataMap := make(map[string]any, 20)
|
dataMap := make(map[string]any, 20)
|
||||||
for _, f := range filters {
|
for _, f := range filters {
|
||||||
dataMap[f.Name] = template.HTML(strings.Join(f.Results, ", "))
|
dataMap[f.Name] = template.HTML(strings.Join(f.Results, ", "))
|
||||||
|
dataMap[f.Name+"_Type"] = f.Type
|
||||||
|
dataMap[f.Name+"_Var1"] = f.Var1
|
||||||
|
dataMap[f.Name+"_Var2"] = f.Var2
|
||||||
|
dataMap[f.Name+"_Var3"] = f.Var3
|
||||||
}
|
}
|
||||||
|
|
||||||
dataMap["WatchName"] = template.HTML(watch.Name)
|
dataMap["WatchName"] = template.HTML(watch.Name)
|
||||||
|
@ -1106,7 +1124,7 @@ func notifyFilter(filters []Filter, filter *Filter, watch *Watch, web *Web, debu
|
||||||
var buffer bytes.Buffer
|
var buffer bytes.Buffer
|
||||||
tmpl.Execute(&buffer, dataMap)
|
tmpl.Execute(&buffer, dataMap)
|
||||||
if debug {
|
if debug {
|
||||||
log.Println(buffer.String())
|
filter.Results = append(filter.Results, buffer.String())
|
||||||
} else {
|
} else {
|
||||||
notifier := filter.Var2
|
notifier := filter.Var2
|
||||||
if notifier == nil {
|
if notifier == nil {
|
||||||
|
|
Loading…
Add table
Reference in a new issue