only things connected to the schedule are processed (unless editing)
This commit is contained in:
parent
34e456ab33
commit
39b2aa2e10
3 changed files with 21 additions and 10 deletions
8
main.go
8
main.go
|
@ -135,7 +135,7 @@ func (web *Web) initCronJobs() {
|
|||
web.cronWatch = make(map[uint]cron.Entry, len(cronFilters))
|
||||
web.cron = cron.New()
|
||||
for _, cronFilter := range cronFilters {
|
||||
entryID, err := web.cron.AddFunc(cronFilter.Var1, func() { triggerSchedule(cronFilter.WatchID, web) })
|
||||
entryID, err := web.cron.AddFunc(cronFilter.Var1, func() { triggerSchedule(cronFilter.WatchID, web, &cronFilter.ID) })
|
||||
if err != nil {
|
||||
log.Println("Could not start job for Watch: ", cronFilter.WatchID)
|
||||
continue
|
||||
|
@ -305,7 +305,7 @@ func (web *Web) watchEdit(c *gin.Context) {
|
|||
}
|
||||
|
||||
buildFilterTree(filters, connections)
|
||||
processFilters(filters, web, &watch, true)
|
||||
processFilters(filters, web, &watch, true, nil)
|
||||
|
||||
c.HTML(http.StatusOK, "watchEdit", gin.H{
|
||||
"Watch": watch,
|
||||
|
@ -367,7 +367,7 @@ func (web *Web) watchUpdate(c *gin.Context) {
|
|||
if filter.Type != "cron" {
|
||||
continue
|
||||
}
|
||||
entryID, err := web.cron.AddFunc(filter.Var1, func() { triggerSchedule(filter.WatchID, web) })
|
||||
entryID, err := web.cron.AddFunc(filter.Var1, func() { triggerSchedule(filter.WatchID, web, &filter.ID) })
|
||||
if err != nil {
|
||||
log.Println("Could not start job for Watch: ", filter.WatchID, err)
|
||||
continue
|
||||
|
@ -470,7 +470,7 @@ func (web *Web) importWatch(c *gin.Context) {
|
|||
}
|
||||
for _, filter := range export.Filters {
|
||||
if filter.Type == "cron" {
|
||||
entryID, err := web.cron.AddFunc(filter.Var1, func() { triggerSchedule(filter.WatchID, web) })
|
||||
entryID, err := web.cron.AddFunc(filter.Var1, func() { triggerSchedule(filter.WatchID, web, &filter.ID) })
|
||||
if err != nil {
|
||||
log.Println("Could not start job for Watch: ", filter.WatchID)
|
||||
continue
|
||||
|
|
22
scraping.go
22
scraping.go
|
@ -22,13 +22,18 @@ import (
|
|||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func processFilters(filters []Filter, web *Web, watch *Watch, debug bool) {
|
||||
func processFilters(filters []Filter, web *Web, watch *Watch, debug bool, scheduleID *uint) {
|
||||
allFilters := filters
|
||||
processedMap := make(map[uint]bool, len(filters))
|
||||
if scheduleID != nil {
|
||||
processedMap[*scheduleID] = true
|
||||
}
|
||||
|
||||
// collect 'store' filters so we can process them separately at the end
|
||||
storeFilters := make([]Filter, 5)
|
||||
for len(filters) > 0 {
|
||||
processedAFilter := true
|
||||
for len(filters) > 0 && processedAFilter {
|
||||
processedAFilter = false
|
||||
filter := &filters[0]
|
||||
filters = filters[1:]
|
||||
if filter.Type == "store" {
|
||||
|
@ -36,9 +41,13 @@ func processFilters(filters []Filter, web *Web, watch *Watch, debug bool) {
|
|||
processedMap[filter.ID] = true
|
||||
continue
|
||||
}
|
||||
|
||||
if len(filter.Parents) == 0 && !debug {
|
||||
continue
|
||||
}
|
||||
var allParentsProcessed = true
|
||||
for _, parent := range filter.Parents {
|
||||
if _, contains := processedMap[parent.ID]; !contains && parent.Type != "cron" {
|
||||
if _, contains := processedMap[parent.ID]; !contains {
|
||||
allParentsProcessed = false
|
||||
break
|
||||
}
|
||||
|
@ -49,6 +58,7 @@ func processFilters(filters []Filter, web *Web, watch *Watch, debug bool) {
|
|||
}
|
||||
getFilterResult(allFilters, filter, watch, web, debug)
|
||||
processedMap[filter.ID] = true
|
||||
processedAFilter = true
|
||||
}
|
||||
|
||||
// process the store filters last
|
||||
|
@ -788,7 +798,7 @@ func notifyFilter(filters []Filter, filter *Filter, watch *Watch, web *Web, debu
|
|||
|
||||
}
|
||||
|
||||
func triggerSchedule(watchID uint, web *Web) {
|
||||
func triggerSchedule(watchID uint, web *Web, scheduleID *uint) {
|
||||
var watch *Watch
|
||||
web.db.Model(&Watch{}).First(&watch, watchID)
|
||||
|
||||
|
@ -798,8 +808,10 @@ func triggerSchedule(watchID uint, web *Web) {
|
|||
var connections []FilterConnection
|
||||
web.db.Model(&FilterConnection{}).Where("watch_id = ?", watch.ID).Find(&connections)
|
||||
|
||||
log.Println("Trigger schedule for", watch.ID, ":", *scheduleID)
|
||||
|
||||
buildFilterTree(filters, connections)
|
||||
processFilters(filters, web, watch, false)
|
||||
processFilters(filters, web, watch, false, scheduleID)
|
||||
}
|
||||
|
||||
func getFilterResultLua(filter *Filter) {
|
||||
|
|
1
todo.md
1
todo.md
|
@ -8,5 +8,4 @@
|
|||
- sms?
|
||||
- etch?
|
||||
- trusted proxies in conf?
|
||||
- only run part of filter tree connected to schedule filter
|
||||
- cron jobs not starting on startup
|
Loading…
Add table
Reference in a new issue