func feedentries_updated() (ReadSource, []ReadEntry, error) { bcms := baidu.NewBcmsProxy(baiduq) var v pubsub.PubsubMessage err := bcms.FetchOneAsJson(&v) if err != nil { return ReadSource{}, nil, err } if (v.Status.StatusCode != 200 && v.Status.StatusCode != 0) || v.Status.Feed == "" { return ReadSource{}, nil, new_backenderror(v.Status.StatusCode, v.Status.StatusReason) } fs := ReadSource{ FeedSource: feed.FeedSource{ Name: v.Title, Uri: v.Status.Feed, Description: v.Subtitle, Period: v.Status.Period / 60, Update: int64(v.Updated), }, LastTouch: int64(unixtime.TimeNow()), NextTouch: int64(unixtime.Time(v.Status.Period) + unixtime.TimeNow()), LastUpdate: int64(unixtime.TimeNow()), } if fs.Period == 0 { fs.Period = 120 // minutes } fes := make([]ReadEntry, len(v.Items)) for idx, i := range v.Items { fes[idx] = ReadEntry{ FeedEntry: feed.FeedEntry{ Uri: i.Uri, Title: i.Title, PubDate: int64(i.Published), Summary: i.Summary, Content: i.Content, Tags: i.Categories, }, } feedentry_init_from_standardlinks(i.StandardLinks, fes[idx]) if fes[idx].Uri == "" { feedentry_init_from_links(i.Links, fes[idx]) } } if err == nil { fes = readentry_filter(fes) fo := new_feedsource_operator() // ignore touch error, because, source may not be subscribed fo.touch(fs.Uri, int64(fs.LastTouch), int64(fs.NextTouch), fs.Period) } log.Println("updated", fs.Name, fs.Update) return fs, fes, err }
func update_work() { backend_context.Lock() defer backend_context.Unlock() w := atomic.AddInt64(&backend_context.working, 1) defer atomic.AddInt64(&backend_context.working, -1) if w != 1 { return } fss, err := feedsource_expired(time.Now().Unix()) if err != nil || len(fss) == 0 { return } idx := rand.Intn(len(fss)) fs := fss[idx] newfs, fes, err := feed_fetch(fs.Uri) newfs.Type = fs.Type newfs.EnableProxy = fs.EnableProxy newfs.Categories = append(newfs.Categories, fs.Categories...) if newfs.Logo == "" { newfs.Logo = fs.Logo } newfs.SubscribeState = fs.SubscribeState newfs.LastTouch = int64(unixtime.TimeNow()) newfs.LastUpdate = newfs.LastTouch newfs.NextTouch = newfs.Period + newfs.LastTouch err = feedsource_save(newfs) fes = readentry_filter(fes) backend_push_update(newfs, fes, err) ps := pubsub.NewSuperFeedrPubSubscriber("async", "Hearts", "Refresh") sc, err := ps.Subscribe(fs.Uri) if err != nil { log.Println("pubsub-google", sc, err) } ps = pubsub.NewGooglePubSubscriber() sc, err = ps.Subscribe(fs.Uri) log.Println("update-tick", fs.Name, sc, err) }