From 01f33939681f149278a597a16c048cb19cad314d Mon Sep 17 00:00:00 2001 From: BroodjeAap Date: Mon, 19 Dec 2022 20:29:11 +0000 Subject: [PATCH] cron filters give a warning when theres an error in var1 --- scraping.go | 45 +++++++++++++++++++++++++++------------------ todo.md | 1 - 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/scraping.go b/scraping.go index 58f2070..c3ca97e 100644 --- a/scraping.go +++ b/scraping.go @@ -15,6 +15,7 @@ import ( "github.com/andybalholm/cascadia" "github.com/antchfx/htmlquery" + "github.com/robfig/cron/v3" "github.com/tidwall/gjson" lualibs "github.com/vadv/gopher-lua-libs" lua "github.com/yuin/gopher-lua" @@ -65,31 +66,32 @@ func processFilters(filters []Filter, web *Web, watch *Watch, debug bool, schedu nextFilters := make([]*Filter, 0, len(currentFilters)) for i := range currentFilters { filter := currentFilters[i] - if filter.Type == "store" { + if filter.Type == "store" { storeFilters = append(storeFilters, filter) - processedMap[filter.ID] = true - continue - } - if debug && filter.Type == "cron" { 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 { - allParentsProcessed = false - break + if debug && filter.Type == "cron" { + processedMap[filter.ID] = true + getCronDebugResult(filter) + continue } - } - if !allParentsProcessed { + if len(filter.Parents) == 0 && !debug { + continue + } + var allParentsProcessed = true + for _, parent := range filter.Parents { + if _, contains := processedMap[parent.ID]; !contains { + allParentsProcessed = false + break + } + } + if !allParentsProcessed { nextFilters = append(nextFilters, filter) - continue - } + continue + } getFilterResult(filters, filter, watch, web, debug) - processedMap[filter.ID] = true + processedMap[filter.ID] = true } if len(nextFilters) == 0 { break @@ -850,6 +852,13 @@ func triggerSchedule(watchID uint, web *Web, scheduleID *uint) { processFilters(filters, web, watch, false, scheduleID) } +func getCronDebugResult(filter *Filter) { + _, err := cron.ParseStandard(filter.Var1) + if err != nil { + filter.log(err) + } +} + func getFilterResultLua(filter *Filter) { L := lua.NewState() defer L.Close() diff --git a/todo.md b/todo.md index 87084d4..41f9f0a 100644 --- a/todo.md +++ b/todo.md @@ -11,5 +11,4 @@ - log things to db for cron runs - comments - db prune job -- add var1 parsing test for cron jobs - add full buildFilterTree/processFilters test \ No newline at end of file