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