예제 #1
0
func (fm FeedManager) updateFeed(f content.Feed) {
	f.Update()

	if f.HasErr() {
		fm.logger.Printf("Error updating feed '%s' database record: %v\n", f, f.Err())
	} else {
		fm.processFeedUpdateMonitors(f)
	}
}
예제 #2
0
파일: hubbub.go 프로젝트: urandom/readeef
func (h Hubbub) subscription(s content.Subscription, f content.Feed, subscribe bool) {
	var err error

	fdata := f.Data()
	u := callbackURL(h.config, h.pattern, fdata.Id)

	body := url.Values{}
	body.Set("hub.callback", u)
	if subscribe {
		h.logger.Infoln("Subscribing to hubbub for " + f.String() + " with url " + u)
		body.Set("hub.mode", "subscribe")
	} else {
		h.logger.Infoln("Unsubscribing to hubbub for " + f.String() + " with url " + u)
		body.Set("hub.mode", "unsubscribe")
	}
	body.Set("hub.topic", fdata.Link)

	buf := util.BufferPool.GetBuffer()
	defer util.BufferPool.Put(buf)

	buf.WriteString(body.Encode())
	req, _ := http.NewRequest("POST", s.Data().Link, buf)
	req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
	req.Header.Add("From", h.config.Hubbub.From)

	resp, err := h.client.Do(req)

	if err != nil {
		err = SubscriptionError{error: err, Subscription: s}
	} else if resp.StatusCode != 202 {
		err = SubscriptionError{error: errors.New("Expected response status 202, got " + resp.Status), Subscription: s}
	}

	if err == nil {
		if subscribe {
			h.subscribe <- s
		} else {
			h.unsubscribe <- s
		}
	} else {
		fdata.SubscribeError = err.Error()
		h.logger.Printf("Error subscribing to hub feed '%s': %s\n", f, err)

		f.Data(fdata)
		f.Update()
		if f.HasErr() {
			h.logger.Printf("Error updating feed database record for '%s': %s\n", f, f.Err())
		}

		h.removeFeed <- f
	}
}