fixed starting cron jobs when importing

This commit is contained in:
BroodjeAap 2022-10-10 19:34:14 +00:00
parent 03f8d8cec7
commit aad3f3437f

18
main.go
View file

@ -419,6 +419,16 @@ func (web *Web) importWatch(c *gin.Context) {
filterMap[filter.ID] = filter
filter.ID = 0
filter.WatchID = uint(watchID)
}
web.db.Delete(&Filter{}, "watch_id = ?", watchID)
if len(export.Filters) > 0 {
tx := web.db.Create(&export.Filters)
if tx.Error != nil {
c.AbortWithError(http.StatusBadRequest, err)
return
}
for _, filter := range export.Filters {
if filter.Type == "cron" {
entryID, err := web.cron.AddFunc(filter.Var1, func() { triggerSchedule(filter.WatchID, web) })
if err != nil {
@ -429,14 +439,6 @@ func (web *Web) importWatch(c *gin.Context) {
web.cronWatch[filter.ID] = web.cron.Entry(entryID)
}
}
web.db.Delete(&Filter{}, "watch_id = ?", watchID)
if len(export.Filters) > 0 {
tx := web.db.Create(&export.Filters)
if tx.Error != nil {
c.AbortWithError(http.StatusBadRequest, err)
return
}
}
web.db.Delete(&FilterConnection{}, "watch_id = ?", watchID)